' Mr. Minich
' Period 1
' Ch4Demo5
' 12/7/2000
' Purpose - Illustrates the use of the Rnd function to create random values

Option Explicit

Private Sub Form_Activate()
    ' sets the appropriate display messages
    
    Randomize
    lblPrompt.Caption = "Enter the number of sides on the die: "
    txtSides.Text = ""
    lblRollResult.Caption = ""
    cmdRoll.Caption = "&Roll"
    cmdClear.Caption = "&Clear"
    cmdExit.Caption = "E&xit"
End Sub

Private Sub cmdRoll_Click()
    ' computes dice roll
    
    Dim intNumSides As Integer            ' number of sides on die
    
    intNumSides = Val(txtSides.Text)
    lblRollResult.Caption = Int(Rnd * intNumSides) + 1  ' computing dice roll

End Sub

Private Sub cmdClear_Click()
    ' clears text box and output label and sets focus appropriately
    
    txtSides.Text = ""
    lblRollResult.Caption = ""
    
    txtSides.SetFocus
End Sub


Private Sub cmdExit_Click()
    ' unloads the form and ends the program
    
    Unload Me
    End
End Sub

' You must use the Randomize statement in the Form_Load event so that the program
'   doesn't repeat the same sequence of random values every time it is executed.

' You must add add one in the Rnd statement so that the dice roll is not zero and so
'   that the highest side can be a result.