Randomize Question
Randomize Question
Randomize Question
Randomize Question
Randomize Question
Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question
Randomize Question Randomize Question
Randomize Question
Go Back  Xtreme Visual Basic Talk > > > Randomize Question


Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2009, 01:18 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default Randomize Question


Hi, I am new to Visual Basic. I am taking a Visual Basic class but its a begginers class. I am trying to write a project that is not for school and I need some help.

What I am trying to do is that I have a Nascar Racing 3 game that I have over 500 tracks for. What I want to do is randomize what track I race at next. I have made a form like this:
http://i293.photobucket.com/albums/m...r824900/N3.jpg

What I want to do is if I click "Superspeedway" for example, when I click random it choose a random track out of the superspeedway list and displays it in the text box.

Now I have looked up the random function and it usually does numbers or an array of numbers. I want to click the random buttom and it shows the track name like "daytona" or "homestead".

So my question is, what is the best way to get this accomplished, do I have to assign the list I make to numbers so each number responds to a track name? Any help would be greatly appreciated. Thank You.
Reply With Quote
  #2  
Old 10-06-2009, 04:30 PM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

If you have made the track names into an array, you should be able to select a random element from the array and place it in the listbox... the array will automatically have a track name associated with each number.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 10-12-2009, 09:38 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Ok , I am trying to make a multidimension array for each of the track lists. I try to do this based on tutorials that I have found. I try to do this but I keep getting the error. "Number of indices is less than the number of dimensions in the indexed array. What am I doing wrong? Here is the code:
Dim Tracks(0 To 32, 0 To 86, 0 To 189, 0 To 88, 0 To 32, 0 To 436) As String
'Dirt Track Tracks
Tracks(0, 0) = "Beach"
Tracks(0, 1) = "Cayuga"
Tracks(0, 2) = "Dbristol"
Tracks(0, 3) = "Ddelwr"
Tracks(0, 4) = "Duquoin3"
Tracks(0, 5) = "Edmonton"
Tracks(0, 6) = "Eldoran3"
Tracks(0, 7) = "Epping"
Tracks(0, 8) = "Evans"
Tracks(0, 9) = "Festival"
Tracks(0, 10) = "Horton"
Tracks(0, 11) = "Libcentr"
Tracks(0, 12) = "Lkptrain"
Tracks(0, 13) = "Lumber"
Tracks(0, 14) = "Lw"
Tracks(0, 15) = "Mars"
Tracks(0, 16) = "Melbrn"
Tracks(0, 17) = "Mnznita"
Tracks(0, 18) = "Mttop"
Tracks(0, 19) = "Myrtle63"
Tracks(0, 20) = "Ncfair"
Tracks(0, 21) = "Nimrod"
Tracks(0, 22) = "Quebec"
Tracks(0, 23) = "Shawano"
Tracks(0, 24) = "Smokeym3"
Tracks(0, 25) = "Spring3"
Tracks(0, 26) = "Swainbro"
Tracks(0, 27) = "Syrcuse"
Tracks(0, 28) = "Valley"
Tracks(0, 29) = "Vegas"
Tracks(0, 30) = "Washton"
Tracks(0, 31) = "Waynecou"
Tracks(0, 32) = "Westvirg"
' Road Courses Tracks
Tracks(1, 0) = "Sticky Fingers"
Tracks(1, 1) = "Beggars Banquet"
Tracks(1, 2) = "Let It Bleed"
Tracks(1, 3) = "Tattoo You"
'Short Track Tracks
Tracks(2, 0) = "eldoran3"
'N3 Speedways
Tracks(3, 0) = "eldoran3"
'N3 Superspeedway
Tracks(4, 0) = "eldoran3"
'All Tracks
Tracks(5, 0) = "eldoran3"
Reply With Quote
  #4  
Old 10-12-2009, 10:26 PM
vb5prgrmrRandomize Question vb5prgrmr is offline
Senior Contributor

* Expert *
 
Join Date: Mar 2009
Posts: 1,087
Default

That is a whole lot of memory you are allocating...
Code:
Dim Tracks(0 To 32, 0 To 86, 0 To 189, 0 To 88, 0 To 32, 0 To 436) As String
Reason is because you are only specifying two of the six dimensions...

Track(0 to 32, 0 to 86,?,?,?,?) = somevalue



Good Luck
Reply With Quote
  #5  
Old 10-13-2009, 09:03 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Quote:
Originally Posted by Iceplug View Post
If you have made the track names into an array, you should be able to select a random element from the array and place it in the listbox... the array will automatically have a track name associated with each number.
Ok, so instead of making a multi dimension array I have made 5 seperate arrays, ranging from 33 to 190 Strings in the array. Now how you pull a random string out of a array?

For example, I have a array named dirt with 33 String names in it, how do I code that if the Radio Button "Dirt Tracks" is checked, then it will display a random string in the Tracks Text Box screen from the Dirt array?

I must be dumb that I can't figure this out.
Any help would be appreciated.
Thanks
JRO248
Reply With Quote
  #6  
Old 10-14-2009, 06:11 AM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Use Random class
Dim RNG As Random
RNG = New Random

Dim N As Integer
N = RNG.Next(3, 64)
This generates a random number that is less than 64, but is no less than 3 - therefore you can get any number from 3 to 63.


EDIT: See two posts down for the 'non .NET' solution.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!

Last edited by Iceplug; 10-14-2009 at 01:08 PM.
Reply With Quote
  #7  
Old 10-14-2009, 08:16 AM
vb5prgrmrRandomize Question vb5prgrmr is offline
Senior Contributor

* Expert *
 
Join Date: Mar 2009
Posts: 1,087
Default

Pssst... Hey Ice, look up and check out which forum you are in...
Reply With Quote
  #8  
Old 10-14-2009, 01:07 PM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Hush you!

Use Rnd function.
Dim N As Integer
N = Int(Rnd * 61) + 3

This will generate a random number that is less than 64 (61 + 3), but is no less than 3 - therefore you can get any number from 3 to 63.
An easy formula for this is, if you want to generate any number from L and H,
N = Int(Rnd * (H - L + 1)) + L
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #9  
Old 10-16-2009, 08:11 AM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Thank You! I have all that done. I have all five of my arrays working and used if statement to get my "all tracks" radio button working. I am now trying to add one more thing to my program.

I have added a textbox and an "Add button" and want I want it to do is if a user want to add another track to the program, they select the type of track from the five options(Radio Buttons), type the track name in the text box, click add and that name will be added to that array. I would also like it if no matter what track type was select it also added every track to the "all tracks" section.

I am not sure if I need to use a loop or just a bunch of if statement. What would be the best way to do this? Here is my code that I used to pull the strings from the arrays to the textbox:

Dim dirtRandom As UInteger
Dim roadRandom As UInteger
Dim tinyRandom As UInteger
Dim speedwayRandom As UInteger
Dim superspeedwayRandom As UInteger
Dim allRandom As UInteger

dirtRandom = Rand(0, 32)
roadRandom = Rand(0, 86)
tinyRandom = Rand(0, 180)
speedwayRandom = Rand(0, 78)
superspeedwayRandom = Rand(0, 28)
allRandom = Rand(0, 4)

If dirtTrackRadioButton.Checked Then
TracksTextBox.Text = Dirt(dirtRandom)
ElseIf roadCourseRadioButton.Checked Then
TracksTextBox.Text = Road(roadRandom)
ElseIf shortTrackRadioButton.Checked Then
TracksTextBox.Text = Tiny(tinyRandom)
ElseIf speedwayRadioButton.Checked Then
TracksTextBox.Text = Speedways(speedwayRandom)
ElseIf superspeedwayRadioButton.Checked Then
TracksTextBox.Text = Superspeedways(superspeedwayRandom)
End If

If allRadioButton.Checked Then
If allRandom = 0 Then
TracksTextBox.Text = Dirt(dirtRandom)
ElseIf allRandom = 1 Then
TracksTextBox.Text = Road(roadRandom)
ElseIf allRandom = 2 Then
TracksTextBox.Text = Tiny(tinyRandom)
ElseIf allRandom = 3 Then
TracksTextBox.Text = Speedways(speedwayRandom)
ElseIf allRandom = 4 Then
TracksTextBox.Text = Superspeedways(superspeedwayRandom)
End If
End If
Reply With Quote
  #10  
Old 10-16-2009, 10:18 AM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

What is Dirt, Road, Tiny, Speedways, and Superspeedways?
Are they arrays or functions?
Where is the list of all tracks?

In order to add elements to an array, you may have to use a dynamic array, because with a regular array, you could run out of space.
However, you cannot Redim Preserve a multi-dimensional array, so you may have to redesign your arrays if they are still 2D arrays.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #11  
Old 10-16-2009, 01:27 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Dirt, Road, Tiny, Speedway, and Superspeedway are my arrays. There are really long so I didn't put them in here the first time. I had trouble with mutlidimension arrays before, so I made them into 5 seperate arrays:

Dirt (held dirt tracks) items went from 0 to 32
Road(held road courses) items went from 0 to 86
Tiny(held short tracks) items went from 0 to 180
Speedways(held Speedways) items went from 0 to 78
Superspeedways( held Superspeedway Tracks) went from 0 to 28
I basically called these arrays to display depending on what Radio Button was selected.

For the all tracks Radio Button, I assigned a random number variable that was from 0 to 4, and if the number was 0 it would pull from the dirt array, etc.

I guess my question is now if I have to make a multdimensional array to be able to put new tracks into arrays. How do I set that up?
Here is my arrays which came above my other code I posted.

Dim Dirt(40) As String
Dirt(0) = "Beach"
Dirt(1) = "Cayuga"
Dirt(2) = "Dbristol"
Dirt(3) = "Ddelwr"
Dirt(4) = "Duquoin3"
Dirt(5) = "Edmonton"
Dirt(6) = "Eldoran3"
Dirt(7) = "Epping"
Dirt(8) = "Evans"
Dirt(9) = "Festival"
Dirt(10) = "Horton"
Dirt(11) = "Libcentr"
Dirt(12) = "Lkptrain"
Dirt(13) = "Lumber"
Dirt(14) = "Lw"
Dirt(15) = "Mars"
Dirt(16) = "Melbrn"
Dirt(17) = "Mnznita"
Dirt(18) = "Mttop"
Dirt(19) = "Myrtle63"
Dirt(20) = "Ncfair"
Dirt(21) = "Nimrod"
Dirt(22) = "Quebec"
Dirt(23) = "Shawano"
Dirt(24) = "Smokeym3"
Dirt(25) = "Spring3"
Dirt(26) = "Swainbro"
Dirt(27) = "Syrcuse"
Dirt(28) = "Valley"
Dirt(29) = "Vegas"
Dirt(30) = "Washton"
Dirt(31) = "Waynecou"
Dirt(32) = "Westvirg"

' Road Courses Tracks
Dim Road(90) As String
Road(0) = "Adelaide"
Road(1) = "AlbanyRc"
Road(2) = "Austral"
Road(3) = "Bahamas"
Road(4) = "Bathurst"
Road(5) = "Bluemt"
Road(6) = "Brainerd"
Road(7) = "Brands"
Road(8) = "Brandz"
Road(9) = "Bullrun3"
Road(10) = "Bulrun2k"
Road(11) = "Clevland"
Road(12) = "Clevland (night)"
Road(13) = "Colorado (Road Course)"
Road(14) = "Crystal"
Road(15) = "Daytonar"
Road(16) = "Desert"
Road(17) = "Detroit"
Road(18) = "Felton"
Road(19) = "Fir"
Road(20) = "France"
Road(21) = "Germany"
Road(22) = "Glen06"
Road(23) = "GlenBoot"
Road(24) = "Glnmore"
Road(25) = "Goodwood"
Road(26) = "Hanabay"
Road(27) = "Hawaii"
Road(28) = "Heartlnd"
Road(29) = "Houston"
Road(30) = "Hutch"
Road(31) = "Imola"
Road(32) = "Imsroad"
Road(33) = "Indyf1"
Road(34) = "Infineon"
Road(35) = "Japan"
Road(36) = "Kloster"
Road(37) = "Kyalami"
Road(38) = "Laguna"
Road(39) = "Lastreet"
Road(40) = "Lilrc"
Road(41) = "Lime"
Road(42) = "Longbch"
Road(43) = "Mexico"
Road(44) = "Midohio"
Road(45) = "Monza"
Road(46) = "Mosport"
Road(47) = "Motopark"
Road(48) = "Mty"
Road(49) = "Ndaytrc"
Road(50) = "Ndesert"
Road(51) = "Nfelton"
Road(52) = "Noris"
Road(53) = "North"
Road(54) = "Nurburg"
Road(55) = "Oring"
Road(56) = "Oskar"
Road(57) = "Oulton"
Road(58) = "Palmbch"
Road(59) = "Port67"
Road(60) = "Portland"
Road(61) = "Redrock"
Road(62) = "Resort"
Road(63) = "Richroad"
Road(64) = "Riversid"
Road(65) = "Roada"
Road(66) = "Roadam"
Road(67) = "Roadland"
Road(68) = "Roebling"
Road(69) = "Sandown"
Road(70) = "Seattle"
Road(71) = "Sebring"
Road(72) = "Silver (Road Course)"
Road(73) = "Snett"
Road(74) = "Solitude"
Road(75) = "Sonoran"
Road(76) = "Spa"
Road(77) = "Taladgnf"
Road(78) = "TheGlen"
Road(79) = "Tillman"
Road(80) = "Toronto"
Road(81) = "Trp (Road Course)"
Road(82) = "Vancouvr"
Road(83) = "Virginia"
Road(84) = "Washton"
Road(85) = "Willow (Road Course)"
Road(86) = "Zandvort"
' Short Tracks
Dim Tiny(190) As String
Tiny(0) = "70savana"
Tiny(1) = "141"
Tiny(2) = "Ace1"
Tiny(3) = "Airborne"
Tiny(4) = "Albanyms"
Tiny(5) = "Anderson"
Tiny(6) = "Augusta"
Tiny(7) = "Bandit"
Tiny(8) = "Battle"
Tiny(9) = "Bchridge"
Tiny(10) = "Berlin"
Tiny(11) = "BigShort"
Tiny(12) = "Bir"
Tiny(13) = "Black"
Tiny(14) = "Blackice"
Tiny(15) = "Bowman"
Tiny(16) = "Bristol"
Tiny(17) = "Bristol (NL)"
Tiny(18) = "Bullring"
Tiny(19) = "Cajon"
Tiny(20) = "Caraway"
Tiny(21) = "Cayugasp"
Tiny(22) = "Centpa"
Tiny(23) = "Chemung"
Tiny(24) = "Coastal"
Tiny(25) = "Colorado (Short Track)"
Tiny(26) = "Concord"
Tiny(27) = "Crater"
Tiny(28) = "Cyclone"
Tiny(29) = "Daybany"
Tiny(30) = "Delawr"
Tiny(31) = "Dirp"
Tiny(32) = "Dnashvll"
Tiny(33) = "Dsouthr"
Tiny(34) = "Dyers"
Tiny(35) = "Eastroy"
Tiny(36) = "Ecms"
Tiny(37) = "Eight6"
Tiny(38) = "Elko"
Tiny(39) = "Evergrn"
Tiny(40) = "Ecpoprk"
Tiny(41) = "Factory"
Tiny(42) = "Fairgrnd"
Tiny(43) = "Federat"
Tiny(44) = "Flamboro"
Tiny(45) = "Flatrock"
Tiny(46) = "Fleming"
Tiny(47) = "Gaintlsp"
Tiny(48) = "Gfrlrwy"
Tiny(49) = "Greenp2k"
Tiny(50) = "Grundyco"
Tiny(51) = "Hawkeye"
Tiny(52) = "Heights"
Tiny(53) = "Hialeah"
Tiny(54) = "Hickory"
Tiny(55) = "Hill"
Tiny(56) = "Hixburg"
Tiny(57) = "Holland"
Tiny(58) = "Hornet"
Tiny(59) = "Hplains"
Tiny(60) = "Hudson"
Tiny(61) = "Huntsvil"
Tiny(62) = "Huricane"
Tiny(63) = "I3"
Tiny(64) = "I70"
Tiny(65) = "Illiana"
Tiny(66) = "Iowa"
Tiny(67) = "Irp"
Tiny(68) = "Irwindal"
Tiny(69) = "Jnnrstwn"
Tiny(70) = "Jungle"
Tiny(71) = "Junkyard"
Tiny(72) = "Kenora"
Tiny(73) = "Klrp"
Tiny(74) = "Lacrosse"
Tiny(75) = "Lakegen"
Tiny(76) = "Lanier"
Tiny(77) = "Lee"
Tiny(78) = "Legacy"
Tiny(79) = "Les"
Tiny(80) = "Lexingtn"
Tiny(81) = "Lkptasph"
Tiny(82) = "Lonesome"
Tiny(83) = "Lorain"
Tiny(84) = "Louville"
Tiny(85) = "Lynburg"
Tiny(86) = "Madison"
Tiny(87) = "Mans4"
Tiny(88) = "Marsasph"
Tiny(89) = "Memorial"
Tiny(90) = "Memphis"
Tiny(91) = "Mesa"
Tiny(92) = "Midvale"
Tiny(93) = "Midway"
Tiny(94) = "Missouf"
Tiny(95) = "Mobile"
Tiny(96) = "Moose"
Tiny(97) = "Mosporto"
Tiny(98) = "Mosquito"
Tiny(99) = "Mrtnsvil"
Tiny(100) = "Mtlawn"
Tiny(101) = "Myrtle"
Tiny(102) = "N3stockt"
Tiny(103) = "N141"
Tiny(104) = "Nashvill"
Tiny(105) = "Nbristol"
Tiny(106) = "Nchenoa"
Tiny(107) = "Neastroy"
Tiny(108) = "Nelko"
Tiny(109) = "Nemesis"
Tiny(110) = "Newriver"
Tiny(111) = "Ngreenp2k"
Tiny(112) = "Nhyattvl"
Tiny(113) = "Nlexingt"
Tiny(114) = "Nmarty"
Tiny(115) = "Nmidval"
Tiny(116) = "Nmosporto"
Tiny(117) = "Nmyrtle"
Tiny(118) = "Nnashvil"
Tiny(119) = "Nomad"
Tiny(120) = "Nrichmon"
Tiny(121) = "Nrmr"
Tiny(122) = "Nsouthr"
Tiny(123) = "Nturmoil"
Tiny(124) = "Nwilliam"
Tiny(125) = "Oak"
Tiny(126) = "Oilcity"
Tiny(127) = "Ona"
Tiny(128) = "Orangec"
Tiny(129) = "Outlaw"
Tiny(130) = "Oxfrdpln"
Tiny(131) = "Pete"
Tiny(132) = "Pine"
Tiny(133) = "Pocomods"
Tiny(134) = "Portoval"
Tiny(135) = "Pss3"
Tiny(136) = "Racecity"
Tiny(137) = "Richmond"
Tiny(138) = "RichNL"
Tiny(139) = "Ridge"
Tiny(140) = "Rimrock"
Tiny(141) = "Rivrhdn3"
Tiny(142) = "Roanoke"
Tiny(143) = "Rockford"
Tiny(144) = "Rpsn3"
Tiny(145) = "Salem"
Tiny(146) = "Sanjose (Short Track)"
Tiny(147) = "Saugus"
Tiny(148) = "Sboston"
Tiny(149) = "Seekonk"
Tiny(150) = "Silver (Short Track)"
Tiny(151) = "Smrsid"
Tiny(152) = "Smsn3"
Tiny(153) = "Smyrna"
Tiny(154) = "Sprngfld"
Tiny(155) = "Stadium"
Tiny(156) = "Stafford"
Tiny(157) = "Starn3"
Tiny(158) = "Sthside"
Tiny(159) = "Summit"
Tiny(160) = "Svalley"
Tiny(161) = "Thndrn3"
Tiny(162) = "Thompson"
Tiny(163) = "Toledo"
Tiny(164) = "Toledop"
Reply With Quote
  #12  
Old 10-16-2009, 01:28 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

This is just some of it. I couldn't make it all fit
Reply With Quote
  #13  
Old 10-16-2009, 01:56 PM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

No, you don't need to make a multidimensional array... you can make a dynamic array fine.

First thing you do for your dynamic array is to declare the array like this:
Dim Dirt() As String
This is a dynamic array - you can change the number of items in the array.
To size the array initially use Redim
Redim Dirt(0 To 40)
as appropriate.

When you want to add an item to the array, you will have to raise the size of the array -
Redim Dirt(0 To 41) will increase the size of the array, but if you don't know what the size of the array should be, use the UBound() function to help you.
X = UBound(Dirt)
Redim Dirt(0 To X + 1)


Now, that increases the size of the array to one larger than it was previously.
The last problem that you might have is, if you use Redim, the contents of the array are deleted.
In order to keep the old information in the array, use Redim Preserve. This will set up some memory for the new array and then copy over all of the elements of the old array into the new array.
Example
X = UBound(Dirt)
Redim Preserve Dirt(0 To X + 1)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #14  
Old 10-16-2009, 02:36 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Thanks that helps a lot! One more thing, I wrote all this code I showed you underneath the Randomize Buttom. I am trying to write the new code under the addButton becuase that will be the button they will click to add the track. When I try to reference a array such as "Dirt" it says "Dirt is not initalized" Do I have to put the arrays in their own function in order for multipl buttons to pull from the same array?
Reply With Quote
  #15  
Old 10-16-2009, 05:35 PM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You should initialize the arrays as soon as the form is loaded.
Redim Dirt(0 To 40) and etc.
in Form_Load for example... therefore the arrays are already created and any button can access the array information.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #16  
Old 10-16-2009, 09:00 PM
mkaras's Avatar
mkarasRandomize Question mkaras is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Mar 2004
Location: Beaverton, OR
Posts: 1,874
Default

I would additionally add that the arrays want to be declared (Dim'ed) on the form outside of any subroutine or event routine so that every routine on the form can see them.

This falls into the subject of variable scoping which you may want to read up on.

mkaras
Reply With Quote
  #17  
Old 10-17-2009, 10:27 AM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Ok, I have tried to put the arrays at the way top so the top of my form looks like this:
Public Class N3Random
'Dirt Track Tracks
Dim Dirt(40) As String
Dirt(0) = "Beach"
Dirt(1) = "Cayuga"
Dirt(2) = "Dbristol"
Dirt(3) = "Ddelwr"
Dirt(4) = "Duquoin3"
Dirt(5) = "Edmonton"
Dirt(6) = "Eldoran3"
Dirt(7) = "Epping"
Dirt(8) = "Evans"
Dirt(9) = "Festival"
Dirt(10) = "Horton"
Dirt(11) = "Libcentr"
Dirt(12) = "Lkptrain"
Dirt(13) = "Lumber"
Dirt(14) = "Lw"
Dirt(15) = "Mars"
Dirt(16) = "Melbrn"
Dirt(17) = "Mnznita"
Dirt(18) = "Mttop"
Dirt(19) = "Myrtle63"
Dirt(20) = "Ncfair"
Dirt(21) = "Nimrod"
Dirt(22) = "Quebec"
Dirt(23) = "Shawano"
Dirt(24) = "Smokeym3"
Dirt(25) = "Spring3"
Dirt(26) = "Swainbro"
Dirt(27) = "Syrcuse"
Dirt(28) = "Valley"
Dirt(29) = "Vegas"
Dirt(30) = "Washton"
Dirt(31) = "Waynecou"
Dirt(32) = "Westvirg"

' Road Courses Tracks
Dim Road(90) As String
Road(0) = "Adelaide"
Road(1) = "AlbanyRc"
Road(2) = "Austral"
Road(3) = "Bahamas"
Road(4) = "Bathurst"
Road(5) = "Bluemt"
Road(6) = "Brainerd"
Road(7) = "Brands"
Road(8) = "Brandz"
Road(9) = "Bullrun3"
Road(10) = "Bulrun2k"
Road(11) = "Clevland"
Road(12) = "Clevland (night)"
Road(13) = "Colorado (Road Course)"
Road(14) = "Crystal"
Road(15) = "Daytonar"
Road(16) = "Desert"
Road(17) = "Detroit"
Road(18) = "Felton"
Road(19) = "Fir"
Road(20) = "France"
Road(21) = "Germany"
Road(22) = "Glen06"
Road(23) = "GlenBoot"
Road(24) = "Glnmore"
Road(25) = "Goodwood"
Road(26) = "Hanabay"
Road(27) = "Hawaii"
Road(28) = "Heartlnd"
Road(29) = "Houston"
Road(30) = "Hutch"
Road(31) = "Imola"
Road(32) = "Imsroad"
Road(33) = "Indyf1"
Road(34) = "Infineon"
Road(35) = "Japan"
Road(36) = "Kloster"
Road(37) = "Kyalami"
Road(38) = "Laguna"
Road(39) = "Lastreet"
Road(40) = "Lilrc"
Road(41) = "Lime"
Road(42) = "Longbch"
Road(43) = "Mexico"
Road(44) = "Midohio"
Road(45) = "Monza"
Road(46) = "Mosport"
Road(47) = "Motopark"
Road(48) = "Mty"
Road(49) = "Ndaytrc"
Road(50) = "Ndesert"
Road(51) = "Nfelton"
Road(52) = "Noris"
Road(53) = "North"
Road(54) = "Nurburg"
Road(55) = "Oring"
Road(56) = "Oskar"
Road(57) = "Oulton"
Road(58) = "Palmbch"
Road(59) = "Port67"
Road(60) = "Portland"

I looked up scope and it said that I could use Dim to declare it at the modular level, but I keep getting an error that says "Declaration expected". What am I doing wrong?
Reply With Quote
  #18  
Old 10-17-2009, 04:48 PM
Iceplug's Avatar
IceplugRandomize Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Public Class N3Random
^^^ that's not a form, that's a class... unless you are using .NET
You should have the declares at the top of the form and the big initialization in the Form_Load.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #19  
Old 10-17-2009, 05:27 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

I got it to work! Thank You so much for all your help! I really appreciate it!
Reply With Quote
  #20  
Old 10-17-2009, 06:02 PM
JRO248 JRO248 is offline
Freshman
 
Join Date: Oct 2009
Posts: 28
Default

Wait a minute, now I have this code that I showed you before:
If dirtTrackRadioButton.Checked Then
TracksTextBox.Text = Dirt(dirtRandom)
ElseIf roadCourseRadioButton.Checked Then
TracksTextBox.Text = Road(roadRandom)
ElseIf shortTrackRadioButton.Checked Then
TracksTextBox.Text = Tiny(tinyRandom)
ElseIf speedwayRadioButton.Checked Then
TracksTextBox.Text = Speedways(speedwayRandom)
ElseIf superspeedwayRadioButton.Checked Then
TracksTextBox.Text = Superspeedways(superspeedwayRandom)
End If

If allRadioButton.Checked Then
If allRandom = 0 Then
TracksTextBox.Text = Dirt(dirtRandom)
ElseIf allRandom = 1 Then
TracksTextBox.Text = Road(roadRandom)
ElseIf allRandom = 2 Then
TracksTextBox.Text = Tiny(tinyRandom)
ElseIf allRandom = 3 Then
TracksTextBox.Text = Speedways(speedwayRandom)
ElseIf allRandom = 4 Then
TracksTextBox.Text = Superspeedways(superspeedwayRandom)
End If
End If

And now the error pops up underneath the arrays and said that "Dirt" (for example) is not initialized. I put the array underneath the Form_load section. Is there I different way I need to call these arrays since there not in this event and in the form load section??
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Randomize Question
Randomize Question
Randomize Question Randomize Question
Randomize Question
Randomize Question
Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question Randomize Question
Randomize Question
Randomize Question
 
Randomize Question
Randomize Question
 
-->