Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB6,VBS
Expertise: beginner
Feb 3, 2001

GetUSStates - Get the list of US States and their abbreviations

' return the list of US States and their abbreviations
'
' returns a bi-dimensional array organized in this way
'         res(n, 0) holds the state's name
'         res(n, 1) holds the state's abbreviation
' the array is sorted on states' names
'
' Example: load the states' names and abbreviations in a combobox
'          Dim st() As String, i As Integer
'          st() = GetUSStates()
'          For i = 0 To UBound(st)
'              Combo1.AddItem st(i, 1) & vbTab & st(i, 0)
'          Next


Function GetUSStates() As String()
    Dim temp() As String
    Dim states(0 To 49, 0 To 1) As String
    Dim i As Integer
    
    ' semi-colon delimited list of US states
    ' note that it can't be longer than 10 lines
    Const STATES_LIST = "Alabama;AL;Alaska;AK;Arizona;AZ;Arkansas;AR;California;" _
        & "CA;" & "Colorado;CO;Connecticut;CT;Delaware;DE;Florida;FL;Georgia;GA;" _
        & "" & "Hawaii;HI;Idaho;ID;Illinois;IL;Indiana;IN;Iowa;IA;" & _
        "Kansas;KS;Kentucky;KY;Louisiana;LA;Maine;ME;Maryland;MD;" & _
        "Massachusetts;MA;Michigan;MI;Minnesota;MN;Mississippi;MS;Missouri;MO;" _
        & "Montana;MT;Nebraska;NE;Nevada;NV;New Hampshire;NH;New Jersey;NJ;" & _
        "New Mexico;NM;New York;NY;North Carolina;NC;North Dakota;ND;Ohio;OH;" _
        & "Oklahoma;OK;Oregon;OR;Pennsylvania;PA;Rhode Island;RI;South " _
        & "Carolina;SC;" & _
        "South Dakota;SD;Tennessee;TN;Texas;TX;Utah;UT;Vermont;VT;" & _
        "Virginia;VA;Washington;WA;West Virginia;WV;Wisconsin;WI;Wyoming;WY"
    ' get a temporary array
    temp() = Split(STATES_LIST, ";")
    
    ' load into the result array
    For i = 0 To UBound(states)
        states(i, 0) = temp(i * 2)
        states(i, 1) = temp(i * 2 + 1)
    Next
    
    ' assign to the result
    GetUSStates = states
End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date