This just goes to show why you shouldn't use text boxes to hold numbers for calculations.
It's also a good example of why Option Strict should be turned on.
try this:
-tgCode:Private Sub butRoll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRoll.Click Dim RandNum, i As Integer Dim RandomClass As New Random() dim rollCount as Integer = CInt(txtD3.Text) 'But only if you can guarantee it's a number... other wise use TryParse... dim rollTotal as Integer = 0 'Initializes the counter 'if at least one dice is rolled If txtD3.Text > 0 Then For i = 0 To rollCount 'roll the dice and add to total -- you do realize you get an extra roll here, right? If I enter 3.... it'll go from 0 to 3... which is 4 iterations.. 'generate a number > or equal to 1 and < 4 RandNum = RandomClass.Next(1, 4) 'txtLastRoll.Text = RandNum 'last number generated <-- honestly... this will only ever keep the last number rolled, so what's the point? txt1.Text = rollTotal.ToString 'whats the value of txtTotal? 'add latest dice roll to total rollTotal += RandNum txt2.text = rollTotal.ToString 'whats the value of txtTotal now? Next i 'roll the next dice End If End Sub




Reply With Quote
