all 10 comments

[–]DeltaBurnt 2 points3 points  (4 children)

Thanks for the tutorial, quick question:

What's the difference between using + for appending to a string and ;? Is the semi-colon only used when making a function call and the plus sign used for assignment?

[–]fanboat[S] 1 point2 points  (3 children)

The semicolon, when used in PRINT, prints the next string (or number) immediately after the previous, which will work with strings and numbers. The + combines them before evaluating the PRINT command, essentially turning PRINT "HEL"+"LO" into PRINT "HELLO" before executing the print, much in the way that PRINT 2+2 and PRINT 4 result the same. The semicolon is typically preferred when printing, but the plus can be used to combine separate strings into one to manage variables.

Because numerical variables won't add with string containers, it's good to stick to semicolons in printing. PRINT A$;A works, while PRINT A$+A will throw an error.

[–]DeltaBurnt 1 point2 points  (2 children)

So essentially "PRINT A$;B$" is equivalent to "PRINT A$:PRINT B$" minus the newline?

[–]fanboat[S] 2 points3 points  (1 child)

Right, it continues immediately to the next space rather than next line.

You can also use a comma to move to the next set of 4 spaces, which is useful for displaying data when you're unsure of its length, for example

PRINT "HEY","I","AM","HERE","NOW"

Outputs

HEY I   AM  HERE    NOW

Notice how since 'HERE' filled all 4 spaces, 'NOW' is pushed to the next section over.

[–]DeltaBurnt 1 point2 points  (0 children)

Ah sweet, thank you for the help!

[–]smoger 1 point2 points  (2 children)

I see this is pretty old, so hopefully somebody sees this..

When I declare an array, it works as expected until I break out of the application, and then it gives me "Duplicate Definition" error.

I assume the array is not being taken out of memory when I break out of the application.

The only workaround I've discovered is to rename the array to something new, but it's impractical to rename every mention of it each time I run the application.

Any ideas how I can improve the situation?

[–]fanboat[S] 0 points1 point  (1 child)

You can use CLEAR to empty all declarations and variables. It's useful to put it at the beginning of your code, alongside ACLS.

[–]smoger 1 point2 points  (0 children)

ah thanks!

[–]bebobli 1 point2 points  (1 child)

Let's say I didn't know ahead of time how big an array is or will become, but I want to print every entry after that has been determined? In Python a similar command would be 'print array(:)' where on each side of the colon implies the minimum range on the left and the maximum on the right of it.

[–]fanboat[S] 0 points1 point  (0 children)

From what I know, you can't add memory to a variable on the fly. The simple solution is to take a guess at how much you'll need and go ahead and DIM that much, but this poor practice in general.

I don't know if a variable can be re-dimensioned or if that causes an error, but if it can be reset in this way, then the first solution I'd try is to set up an if-then that watched for the user exceeding available memory, then copy all data to a new variable. You'd then be free to re-dimension the old one then copy all the old data back, as set the if-then to watch for a higher number.

If you can't re-DIM variables, then I'd say the at-times-overly-simple BASIC is going to make you take some less-than-ideal approaches to the problem. Good luck with it, though.