Results 1 to 3 of 3

Thread: need to look in array...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    16

    Exclamation need to look in array...

    i need to make a program that i enter in a state name and the program will produce the abbreviations to it in a different box. I know i have to use arrays but other than that i have no clue. please help

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: need to look in array...

    These 2 functions should help you out.. i use them all the time because the software I write is often data entry..

    VB Code:
    1. Public Shared Function GetAbbrFromState(ByVal StateName As String) As String
    2.             Select Case StateName
    3.                 Case "Alabama" : Return "AL"
    4.                 Case "Alaska" : Return "AK"
    5.                 Case "Arizona" : Return "AZ"
    6.                 Case "Arkansas" : Return "AR"
    7.                 Case "California" : Return "CA"
    8.                 Case "Colorado" : Return "CO"
    9.                 Case "Connecticut" : Return "CT"
    10.                 Case "Delaware" : Return "DE"
    11.                 Case "District of Columbia" : Return "DC"
    12.                 Case "Florida" : Return "FL"
    13.                 Case "Georgia" : Return "GA"
    14.                 Case "Hawaii" : Return "HI"
    15.                 Case "Idaho" : Return "ID"
    16.                 Case "Illinois" : Return "IL"
    17.                 Case "Indiana" : Return "IN"
    18.                 Case "Iowa" : Return "IA"
    19.                 Case "Kansas" : Return "KS"
    20.                 Case "Kentucky" : Return "KY"
    21.                 Case "Louisiana" : Return "LA"
    22.                 Case "Maine" : Return "ME"
    23.                 Case "Maryland" : Return "MD"
    24.                 Case "Massachusetts" : Return "MA"
    25.                 Case "Michigan" : Return "MI"
    26.                 Case "Minnesota" : Return "MN"
    27.                 Case "Mississippi" : Return "MS"
    28.                 Case "Missouri" : Return "MO"
    29.                 Case "Montana" : Return "MT"
    30.                 Case "Nebraska" : Return "NE"
    31.                 Case "Nevada" : Return "NV"
    32.                 Case "New Hampshire" : Return "NH"
    33.                 Case "New Jersey" : Return "NJ"
    34.                 Case "New Mexico" : Return "NM"
    35.                 Case "New York" : Return "NY"
    36.                 Case "None/Other" : Return "XX"
    37.                 Case "North Carolina" : Return "NC"
    38.                 Case "North Dakota" : Return "ND"
    39.                 Case "Ohio" : Return "OH"
    40.                 Case "Oklahoma" : Return "OK"
    41.                 Case "Oregon" : Return "OR"
    42.                 Case "Pennsylvania" : Return "PA"
    43.                 Case "Rhode Island" : Return "RI"
    44.                 Case "South Carolina" : Return "SC"
    45.                 Case "South Dakota" : Return "SD"
    46.                 Case "Tennessee" : Return "TN"
    47.                 Case "Texas" : Return "TX"
    48.                 Case "Utah" : Return "UT"
    49.                 Case "Vermont" : Return "VT"
    50.                 Case "Virginia" : Return "VA"
    51.                 Case "Washington" : Return "WA"
    52.                 Case "West Virginia" : Return "WV"
    53.                 Case "Wisconsin" : Return "WI"
    54.                 Case "Wyoming" : Return "WY"
    55.                 Case Else : Return String.Empty
    56.             End Select
    57.         End Function
    58.  
    59.         Public Function GetNameFromAbbr(ByVal Abbr As String) As String
    60.             Select Case Abbr.ToUpper
    61.                 Case "AL" : Return "Alabama"
    62.                 Case "AK" : Return "Alaska"
    63.                 Case "AZ" : Return "Arizona"
    64.                 Case "AR" : Return "Arkansas"
    65.                 Case "CA" : Return "California"
    66.                 Case "CO" : Return "Colorado"
    67.                 Case "CT" : Return "Connecticut"
    68.                 Case "DE" : Return "Delaware"
    69.                 Case "DC" : Return "District of Columbia"
    70.                 Case "FL" : Return "Florida"
    71.                 Case "GA" : Return "Georgia"
    72.                 Case "HI" : Return "Hawaii"
    73.                 Case "ID" : Return "Idaho"
    74.                 Case "IL" : Return "Illinois"
    75.                 Case "IN" : Return "Indiana"
    76.                 Case "IA" : Return "Iowa"
    77.                 Case "KS" : Return "Kansas"
    78.                 Case "KY" : Return "Kentucky"
    79.                 Case "LA" : Return "Louisiana"
    80.                 Case "ME" : Return "Maine"
    81.                 Case "MD" : Return "Maryland"
    82.                 Case "MA" : Return "Massachusetts"
    83.                 Case "MI" : Return "Michigan"
    84.                 Case "MN" : Return "Minnesota"
    85.                 Case "MS" : Return "Mississippi"
    86.                 Case "MO" : Return "Missouri"
    87.                 Case "MT" : Return "Montana"
    88.                 Case "NE" : Return "Nebraska"
    89.                 Case "NV" : Return "Nevada"
    90.                 Case "NH" : Return "New Hampshire"
    91.                 Case "NJ" : Return "New Jersey"
    92.                 Case "NM" : Return "New Mexico"
    93.                 Case "NY" : Return "New York"
    94.                 Case "XX" : Return "None/Other"
    95.                 Case "NC" : Return "North Carolina"
    96.                 Case "ND" : Return "North Dakota"
    97.                 Case "OH" : Return "Ohio"
    98.                 Case "OK" : Return "Oklahoma"
    99.                 Case "OR" : Return "Oregon"
    100.                 Case "PA" : Return "Pennsylvania"
    101.                 Case "RI" : Return "Rhode Island"
    102.                 Case "SC" : Return "South Carolina"
    103.                 Case "SD" : Return "South Dakota"
    104.                 Case "TN" : Return "Tennessee"
    105.                 Case "TX" : Return "Texas"
    106.                 Case "UT" : Return "Utah"
    107.                 Case "VT" : Return "Vermont"
    108.                 Case "VA" : Return "Virginia"
    109.                 Case "WA" : Return "Washington"
    110.                 Case "WV" : Return "West Virginia"
    111.                 Case "WI" : Return "Wisconsin"
    112.                 Case "WY" : Return "Wyoming"
    113.                 Case Else : Return String.Empty
    114.             End Select
    115.         End Function

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: need to look in array...

    here is also code to get all state names in a string array, you could use this code and change the string to be abbreviations too if you wanted an array of the 2 char state names..

    VB Code:
    1. Dim strStateString As String = "Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|District of Columbia|" & _
    2.                                                         "Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|" & _
    3.                                                         "Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|" & _
    4.                                                         "New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|" & _
    5.                                                         "Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming"
    6.  
    7.             Dim States() As String = strStateString.Split("|"c)

Posting Permissions

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



Click Here to Expand Forum to Full Width