Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Roll The Dice InputBox$ and MessageBox Example
#18
Using EmmasPPM's ideas to make more than 1 round and to keep a log of them, here is an updated version. Thanks Emmas!
The limit on rounds is 100, then it will tell you the limit has been reached. 

Code: (Select All)

'Roll The Dice v.2
'Feb. 19, 2025

'Thank you to EmmasPPM for the ideas to make more than 1 round and to keep a log of the rounds.

Dim dice(100)
Dim a$(100)
Dim totals(100)
_Title "Roll The Dice by SierraKen"
Randomize Timer
Do
    Do

        'How many dice.
        title$ = "Roll The Dice"
        defaultInput$ = " "
        message$ = "How many dice do you wish to roll (1-100)?"
        result$ = _InputBox$(title$, message$, defaultInput$)
        If _Trim$(result$) = "" Then End
        diceam = Val(result$)
        If diceam < 1 Or diceam > 100 Or diceam <> Int(diceam) Then
            _MessageBox "Roll The Dice", "Pick only between 1 and 100."
            Exit Do
        End If

        'How many sides.
        title$ = "How many sides."
        defaultInput$ = " "
        message$ = "How many sides is your dice (3-100)?"
        result$ = _InputBox$(title$, message$, defaultInput$)
        If _Trim$(result$) = "" Then End
        num = Val(result$)
        If num < 3 Or num > 100 Or num <> Int(num) Then
            _MessageBox "How many sides.", "Pick only between 3 and 100."
            Exit Do
        End If

        'Roll The Dice
        For t = 1 To diceam
            dice(t) = Int(Rnd * num) + 1
            a$(t) = Str$(dice(t))
            b$ = b$ + "  [ Dice " + Str$(t) + ": " + a$(t) + " ]  "
            total = total + dice(t)
        Next t
        m$ = b$ + " [ Roll Total: " + Str$(total) + " ]"
        _MessageBox "Roll The Dice", m$

        'Round Totals Window
        rounds = rounds + 1
        totals(rounds) = total
        For r = 1 To rounds
            r$ = r$ + " [ Round " + Str$(r) + ":  " + Str$(totals(r)) + " ]  "
        Next r
        _MessageBox "Dice Round Totals Log", r$
        If rounds = 100 Then
            _MessageBox "Limit Reached", "Your 100 round limit has been reached, feel free to play again."
            End
        End If

        'Clear strings and variable for next round.
        m$ = ""
        a$ = ""
        b$ = ""
        r$ = ""
        total = 0
    Loop
Loop
Reply


Messages In This Thread
RE: Roll The Dice InputBox$ and MessageBox Example - by SierraKen - Yesterday, 12:23 AM



Users browsing this thread: 10 Guest(s)