Need help with array and random class

petrina1's Avatar, Join Date: Jan 2011
Newbie 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 shabbir; 27Feb2011 at 09:40.. Reason: Code blocks
pein87's Avatar
Ambitious contributor
you need to add the count of the array elements. or ReDim it. This is visual; basic though and not php.

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


Code: Visual Basic
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 by pein87; 9Mar2011 at 03:57..
shabbir like this