Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Help with Randomizing multiple arrays

$
0
0
First of all, I just downloaded visual basic and never programmed a day in my life before last week. I'm taking a programming class in school and I decided to try my own solution.

Basically what I have so far is program with multiple arrays. What I'm trying to accomplish is figuring out the structure and code of what I want to do. I'm trying to get a message box(or something similar) to display an item from one of several arrays. I figured out how to randomize a single array, but not code to choose an item from multiple arrays.

It's just some stupid idea me and a friend came up with to randomize loadouts in Battlefield 3. Where there are 4 check boxes (Assault,Engineer,Support,Recon) and depending on which ones are checked it throws out class specific loadouts related to that class. I just started this a day ago and came up with the following code. So far I have 3 check boxes disabled and only the assault one enabled trying to debug this first. I'm trying to get the message box to display either an random string from the assault array or shot array and pdw array. I didn't put them all into one array because each group of weapons can have a different set of scopes and attachments etc. So I'm curious on how I would code this to get the result I want. This is just a starting point i have. If the random weapon array chosen is a shotgun, then I want a specific set of scopes to be choses with it etc etc. Thanks in advance!

I would appreciate any responses to not be over critical, I only have 5 hours of programming under my belt. I'm sure there's a better way of organizing this code and simpler than I'm making it and that's why I'm posting.

Public Class BF3Rndm
Dim assault() As String
Dim scope() As String
Dim attachment() As String
Dim attachment2() As String
Dim gadget1() As String
Dim sidearm() As String
Dim spec() As String
Dim pdw() As String
Dim shot() As String
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Close()
End Sub

Private Sub chkAssault_CheckedChanged(sender As Object, e As EventArgs) Handles chkAssault.CheckedChanged
ReDim assault(12)
assault(0) = "M16A3"
assault(1) = "M16A4"
assault(2) = "FAMAS"
assault(3) = "AUG A3"
assault(4) = "M416"
assault(5) = "F2000"
assault(6) = "AEK-971"
assault(7) = "AK-74M"
assault(8) = "AN-94"
assault(9) = "G3A3"
assault(10) = "KH-2002"
assault(11) = "Scar-L"
assault(12) = "L85A2"
'assault(9) = "AS VAL"
Randomize()

ReDim pdw(6)
pdw(0) = "MP7"
pdw(1) = "PP-2000"
pdw(2) = "UMP-45"
pdw(3) = "PDW-R"
pdw(4) = "P90"
pdw(5) = "PP-19"
pdw(6) = "M5K"
Randomize()

ReDim shot(6)
shot(0) = "870MCS"
shot(1) = "M1014"
shot(2) = "Saiga 12K"
shot(3) = "USAS-12"
shot(4) = "SPAS-12"
shot(5) = "DAO-12"
shot(6) = "MK3A1"
Randomize()

ReDim scope(10)
scope(0) = "- Reflex(RDS) Sight"
scope(1) = "- Kobra(RDS) Sight"
scope(2) = "- Holo Sight"
scope(3) = "- PSO-1(4X) Sight"
scope(4) = "- PKA-S(HOLO) Sight"
scope(5) = "- IRNV(IR 1X) Sight"
scope(6) = "- PKS-07(7X) Sight"
scope(7) = "- PK-A(3.4X) Sight"
scope(8) = "- ACOG(4X) Sight"
scope(9) = "- M145(3.4X)"
scope(10) = "- Rifle Scope(6X) Sight"
Randomize()
ReDim attachment(2)
attachment(0) = "- Foregrip"
attachment(1) = "- Bipod"
attachment(2) = "- Underslung"
Randomize()

ReDim attachment2(5)
attachment2(0) = "- Heavy Barrel"
attachment2(1) = "- Flash Suppressor"
attachment2(2) = "- Suppressor"
attachment2(3) = "- Tactical Light"
attachment2(4) = "- Laser Sight"
attachment2(5) = "- No Secondary"
Randomize()

ReDim sidearm(15)
sidearm(0) = "MP412 Rex"
sidearm(1) = ".44 Magnum"
sidearm(2) = ".44 Scoped"
sidearm(3) = "93R"
sidearm(4) = "G17C"
sidearm(5) = "M9 TACT"
sidearm(6) = "MP443 TACT"
sidearm(7) = "G17C SUPP"
sidearm(8) = "M9 SUPP"
sidearm(9) = "MP443 SUPP"
sidearm(10) = "G18"
sidearm(11) = "G18 SUPP"
sidearm(12) = "M1911 TACT"
sidearm(13) = "M1911 SUPP"
sidearm(14) = "M1911"
sidearm(15) = "M1911 S-TAC"
Randomize()

ReDim gadget1(10)
gadget1(0) = "Medic Kit"
gadget1(1) = "M320 Buck"
gadget1(2) = "M26 Frag"
gadget1(3) = "M320 Smoke"
gadget1(4) = "M26 Dart"
gadget1(5) = "M320 LVG"
gadget1(6) = "M26 Slug"
gadget1(7) = "M320"
gadget1(8) = "M26 MASS"
gadget1(9) = "Xbow"
gadget1(10) = "Xbow Scoped"
Randomize()

ReDim spec(6)
spec(0) = "Squad Sprint"
spec(1) = "Squad Ammo"
spec(2) = "Squad Flak"
spec(3) = "Squad Explosives"
spec(4) = "Squad Suppression"
spec(5) = "Squad Cover"
spec(6) = "Squad Frag"
End Sub

Private Sub btnRandom_Click(sender As Object, e As EventArgs) Handles btnRandom.Click
Dim sight As String
Dim attach As String
Dim attach2 As String
Dim weapon As String
Dim gadget As String
Dim secondary As String
Dim special As String
If chkAssault.Checked = True Then
gadget = gadget1(Int(Rnd() * (UBound(gadget1) + 1)))
weapon = assault(Int(Rnd() * (UBound(assault) + 1)))
secondary = sidearm(Int(Rnd() * (UBound(sidearm) + 1)))
sight = scope(Int(Rnd() * (UBound(scope) + 1)))
attach = attachment(Int(Rnd() * (UBound(attachment) + 1)))
attach2 = attachment2(Int(Rnd() * (UBound(attachment2) + 1)))
special = spec(Int(Rnd() * (UBound(spec) + 1)))
MsgBox(weapon & Space(1) & sight & Space(1) & attach & Space(1) & attach2 & vbCrLf & secondary & vbCrLf & gadget & vbCrLf & special)
End If
End Sub
End Class

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>