JustLetMeRegister
Member
- Joined
- Apr 24, 2012
- Messages
- 7
- Programming Experience
- Beginner
Hello,
I'm trying to make a program that notably allows the user to roll two six-sided dice at the same time, and display the result on screen.
For some reason, it doesn't work properly, as the result of each dice is always the same as the other one (it'll always be 1 and 1, or 2 and 2, or 3 and 3, etc.). I don't know why. In the same program, I also allow the user to roll single dice separately, and that, on the other hand, works: it gets different results. It works in the exact same way, except it only rolls one dice at a time instead of two.
I use public functions. Here is the code that calls them when the user clicks on a button:
And here are the functions:
I know both functions are exactly the same but I figured maybe creating a second one, with different variables, would help to get two different results... but no. Both results are always the same, for a reason that escapes me.
Any help would be GREATLY appreciated!
PS: I am new to Visual Basic so maybe it's a dumb mistake... I wouldn't know.
I'm trying to make a program that notably allows the user to roll two six-sided dice at the same time, and display the result on screen.
For some reason, it doesn't work properly, as the result of each dice is always the same as the other one (it'll always be 1 and 1, or 2 and 2, or 3 and 3, etc.). I don't know why. In the same program, I also allow the user to roll single dice separately, and that, on the other hand, works: it gets different results. It works in the exact same way, except it only rolls one dice at a time instead of two.
I use public functions. Here is the code that calls them when the user clicks on a button:
RollDice1() Select Case RollDice1() (...) ' here I insert code that changes an image to display the dice result on screen End Select RollDice2() Select Case RollDice2() (...) ' ditto End Select
And here are the functions:
Public Function RollDice1() As Byte Dim R1 As New Random() Dim R2 As Byte R2 = R1.Next(1, 7) RollDice1 = R2 End Function Public Function RollDice2() As Byte Dim R3 As New Random() Dim R4 As Byte R4 = R3.Next(1, 7) RollDice2 = R4 End Function
I know both functions are exactly the same but I figured maybe creating a second one, with different variables, would help to get two different results... but no. Both results are always the same, for a reason that escapes me.
Any help would be GREATLY appreciated!
PS: I am new to Visual Basic so maybe it's a dumb mistake... I wouldn't know.