Need help with array and random class

Discussion in 'PHP' started by petrina1, Feb 27, 2011.

  1. petrina1

    petrina1 New Member

    Joined:
    Jan 29, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I have these state and capital arrays below; I am trying to create a program that has one label and four radio buttons... When you run the program a question comes up in the label... what is the capital of (state name) ....then four state capitals show up in the radio buttons and you have to make a choice. Need help with random class..... a string to hold the correct anwser.. PLEASE HELP; Thank you in advance

    Code:
    'Declare module level variables
    Private aStates() As String = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", _
    "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", _
    "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", _
    "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", _
    "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", _
    "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", _
    "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"}
     
    Private aCapitals() As String = {"Montgomery", "Juneau", "Phoenix", "Little Rock", "Sacramento", _
    "Denver", "Hartford", "Dover", "Tallahassee", "Atlanta", "Honolulu", "Boise", "Springfield", _
    "Indianapolis", "Des Moines", "Topeka", "Frankfort", "Baton Rouge", "Augusta", "Annapolis", "Boston", _
    "Lansing", "St. Paul", "Jackson", "Jefferson City", "Helena", "Lincoln", "Carson City", "Concord", _
    "Trenton", "Santa Fe", "Albany", "Raleigh", "Bismarck", "Columbus", "Oklahoma City", "Salem", _
    "Harrisburg", "Providence", "Columbia", "Pierre", "Nashville", "Austin", "Salt Lake City", "Montpelier", _
    "Richmond", "Olympia", "Charleston", "Madison", "Cheyenne"}
    
     
    Last edited by a moderator: Feb 27, 2011
  2. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    you need to add the count of the array elements. or ReDim it. This is visual; basic though and not php.

    Code:
    Private MyStates(0 to 49) As String
    MyStates(0) = "Kansas"
    Or

    Code:
    Private MyStates() As String
    
    ReDim MyStates(0 to 49) As String
    
    MyStates(0) = "Kansas"
    As for the class just use a function to select 3 randoms and have it except the actual capital as a param so it can loop through and find it in the array.
     
    Last edited: Mar 8, 2011
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice