add two 6 sided dice rolls
VB.NET Code:
Dim myRandomGenerator As System.Random
'roll1
Dim r1 As Integer
'roll2
Dim r2 As Integer
myRandomGenerator = New System.Random
Label1.Text = myRandomGenerator.Next(1, 7)
Label2.Text = myRandomGenerator.Next(1, 7)
r1 = Val(Label1.Text) 'val()change text to number 'change what control you want (textbox, label, ect)
r2 = Val(Label2.Text) 'val()change text to number 'change what control you want(textbox, label, ect)
Label3.Text = r1 + r2 'add the two random numbers
this is the easiest way i know of.. found a one random number generator on msdn student learning center and made a second one ^^
Re: add two 6 sided dice rolls
I'm a stickler for clean code, and you don't need to assign the randomly generated numbers to Labels and then use VAL() to convert them back to numbers so that you can add them. This does the same thing with way less overhead:
VB Code:
Dim myRandomGenerator As System.Random = New System.Random
Dim r1 As Integer = myRandomGenerator.Next(1, 7)
Dim r2 As Integer = myRandomGenerator.Next(1, 7)
Label1.Text = r1.ToString
Label2.Text = r2.ToString
Label3.Text = r1 + r2
Re: add two 6 sided dice rolls
thanks for the reply.. and i appreciate your input ^^ .. and i now stand *cough corrected your way looks so simple *cough*.. lol thank you
Re: add two 6 sided dice rolls
No problem. I actually created a die roller for my gaming group. We all used laptops and it had "real-time die roll streaming" capabilities that sent the die rolls to each person connected to the host.
I would be more than happy to send you the code. I never fully developed it so the code is really raw and our gaming group started using Fantasy Grounds.
Re: add two 6 sided dice rolls
Cleaner and type-safe code would be this:
Code:
Dim r As New Random()
Dim r1 As Integer = r.Next(1, 7)
Dim r2 As Integer = r.Next(1, 7)
Me.Label1.Text = r1.ToString()
Me.Label2.Text = r2.ToString()
Me.Label3.Text = (r1 + r2).ToString()
Re: add two 6 sided dice rolls
Quote:
Originally Posted by
raineym
No problem. I actually created a die roller for my gaming group. We all used laptops and it had "real-time die roll streaming" capabilities that sent the die rolls to each person connected to the host.
I would be more than happy to send you the code. I never fully developed it so the code is really raw and our gaming group started using Fantasy Grounds.
really?? that would be awesome dude.. id like to give it a try
Re: add two 6 sided dice rolls
Quote:
Originally Posted by
rockyamyx
really?? that would be awesome dude.. id like to give it a try
Just PM me your email address and its all yours.
Re: add two 6 sided dice rolls
thx again.. itll take me sum time to look at it all.. (lots and lots of code but.. at least theres lots and lots of comments lol)