Dice Menu Program

Write a program using the skills you have learned so far to ask the user to select between a 6,12 or 20 sided dice and then to display 5 rolls of that dice. The program should only stop asking when the user enters zero.

Solution after the break

Create a form with a single button and a list box called lstOutput.  Enter the code below into the button (Sorry about the formatting, Glow doesn’t allow me to use a Code box)

  • Dim Counter As Integer
  • Dim userchoice As String
  • Randomize()
  • Do
    • userchoice = LCase(InputBox(“Please enter the dice you want to roll” & vbCrLf & “D6” & vbCrLf & “D12” & vbCrLf & “D20” & vbCrLf & “or 0 (zero) to quit”))
    • LstOutput.Items.Clear()
    • Select Case userchoice
    • Case “d20”
      • LstOutput.Items.Add(“Rolling 5 D20s”)
      • For Counter = 1 To 5
        • LstOutput.Items.Add(Int(Rnd() * 20) + 1)
      • Next
    • Case “d6”
      • LstOutput.Items.Add(“Rolling 5 D6s”)
      • For Counter = 1 To 5
        • LstOutput.Items.Add(Int(Rnd() * 6) + 1)
      • Next
    • Case “d12”
      • LstOutput.Items.Add(“Rolling 5 D12s”)
      • For Counter = 1 To 5
        • LstOutput.Items.Add(Int(Rnd() * 12) + 1)
      • Next
    • Case “0”
      • LstOutput.Items.Add(“Thanks for playing”)
    • Case Else
      • MsgBox(“Please Enter D6,D12,D20 or 0 (Zero)”)
    • End Select
  • Loop Until userchoice = “0”

Screenshots below

  1. What does vbCrLf do?
  2. Why did I use LCase?