Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

VS 2010 Taking track of Dice Rolls using arrays

$
0
0
I'm having a bit of a trouble figuring out how to keep track of how many times a side of a dice has been rolled. I'm new to programming so i don't understand how to use arrays that well. I'm using two 6 sided die's and want to keep track of how many times it got rolled.

I.E If I rolled 4 and 2
It would be like 1:0 2:1 3:0 4:1 5:0 6:0

Code:

'I think I can do it without using arrays but I'm not positive if it's right

Dim intFirstDie As Integer
Dim intSecondDie As Integer
Dim intDie0, intDie1, intDie2, intDie3, intDie4, intDie5 As Integer  'variables to take tally of how many times the dice value is rolled
       
        '
        'without using arrays, you have to name a variable for each die face you can roll:
        intFirstDie = DieRoll() 'A subroutine I wrote to generate the value for the die.
        If intFirstDie = 1 Then
            intDie0 += 1
        ElseIf intFirstDie = 2 Then
            intDie1 += 1
        ElseIf intFirstDie = 3 Then
            intDie2 += 1
        ElseIf intFirstDie = 4 Then
        etc... til intDie5
        End If
        'Same with the intSecondDie
       
    End Sub

It would be appriciated if someone could help me turn that into an array and maybe explain a little so i can learn how to do so on my own in the future?

Cheers,

Nick

Viewing all articles
Browse latest Browse all 42215

Trending Articles



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