-
Dec 2nd, 2010, 03:42 PM
#1
Thread Starter
Member
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 ^^
Last edited by rockyamyx; Dec 2nd, 2010 at 03:44 PM.
Reason: Forgot to wrap code
-
Dec 3rd, 2010, 09:11 AM
#2
Member
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
Michael Rainey
--------------------
OS: Windows 11 Professional
VS: 2022
Level: Intermediate
Controls: ImageComboBox
-
Dec 3rd, 2010, 08:17 PM
#3
Thread Starter
Member
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
-
Dec 3rd, 2010, 08:54 PM
#4
Member
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.
Michael Rainey
--------------------
OS: Windows 11 Professional
VS: 2022
Level: Intermediate
Controls: ImageComboBox
-
Dec 4th, 2010, 12:31 AM
#5
Lively Member
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()
-
Dec 4th, 2010, 08:14 AM
#6
Thread Starter
Member
Re: add two 6 sided dice rolls
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
-
Dec 4th, 2010, 10:30 AM
#7
Member
Re: add two 6 sided dice rolls
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.
Michael Rainey
--------------------
OS: Windows 11 Professional
VS: 2022
Level: Intermediate
Controls: ImageComboBox
-
Dec 4th, 2010, 02:59 PM
#8
Thread Starter
Member
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|