Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice Roller Using Windows Popups
#1
There's no graphics. But it lets you choose between 3 and 100 sides of dice and how many dice in one roll. It also keeps tabs on all of your totals, up to 100 rolls. This also uses windows popups for the entire program. Nothing will be on the main window, besides the very end to turn it off. This is an example on how to use windows popups for the messagebox and inputbox$ commands. Enjoy!

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




Users browsing this thread: 1 Guest(s)