Results 1 to 6 of 6

Thread: Array question

  1. #1

    Array question

    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.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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
    Last edited by Petr Schreiber; 07-02-2011 at 22:06.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Thanks Petr.

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

    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.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    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.

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •