I am new to VB and was wondering if anyone knows how to generate random numbers? Like 1 - 100 or 4D6 were each die is a random accurence then the numbers are added together for an answer.
I thank you for the help.
MLC
Printable View
I am new to VB and was wondering if anyone knows how to generate random numbers? Like 1 - 100 or 4D6 were each die is a random accurence then the numbers are added together for an answer.
I thank you for the help.
MLC
Code:Private Sub Command1_Click()
Dim i As Integer, iNum As Integer, iTotal As Integer
Randomize
For i = 1 To 6
iNum = (Rnd * 100) + 1 'number from 1 to 100
iTotal = iTotal + iNum
Next i
MsgBox iTotal
End Sub
If you want whole numbers (no decimals) then round it off with Int().
VB Code:
iNum = Int(Rnd * 101)