1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Need help with array and random class

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

  1. petrina1

    petrina1 New Member

    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

    '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 New Member

    you need to add the count of the array elements. or ReDim it. This is visual; basic though and not php.

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

    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