PDA

View Full Version : Array question



TheOne
07-02-2011, 20:40
Hi,

I'm new to this so please bear with me. And I hope it is in the right forum.

I'm trying to load an array with the 50 states abbreviation to search for a valid state. Does thinBasic have a limit to the number of columns you can input data/code before it doesn't recognizes it? That's what I think is happening. So I tried to put it into several lines but that didn't work either. Could you provide any insight or help? Thanks.

Dim aStates(50) As String

Array Assign aStates(1) = "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA', "HI", "ID", "IL", "In", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "Or", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"

Noticed too that it change IN to In and OR as Or. Wouldn't leave it in caps.

Thanks again.

Petr Schreiber
07-02-2011, 21:54
Hi TheOne,

welcome to the forums!
The root of your trouble is in fact you made one typo - instead of writing "GA" you wrote "GA'.

You also list 51 entries, but dim array just for 50.

After correcting these two, everything works as expected:



Dim aStates(51) As String

Array Assign aStates(1) = "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"
Maybe it will make you happy that you don't have to use Array Assign at all and you can do directly:

Dim aStates(51) As String

aStates(1) = "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL",
"GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME",
"MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH",
"NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI",
"SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"
Note the implicit line continuation - this feature works from ThinBASIC 1.8.6.0 up


Petr

TheOne
07-02-2011, 22:17
Thanks Petr.

Extra pair of eyes always help. How did I miss those quotes? And how did I have US gain another state? :D

I'm on version 1.8.0.0. How do I explicitly tell thinBasic to continue to the next line for this and other things?

Thanks again Petr.

Petr Schreiber
07-02-2011, 23:19
Hi,

in older versions, the explicit line continuation is achieved via underscore:


Dim aStates(51) As String

aStates(1) = "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", _
"GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", _
"MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", _
"NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", _
"SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"



Petr

TheOne
07-02-2011, 23:26
Thanks again Petr.

Couldn't find anything in the help manual so I originally tried the dash and plus. Never would have thought the underscore. :D