1. Laboratory Activity 3 (Batch 3)
Roll Dice Program
Public Class Form1
Private dice1 As Integer
Private dice2 As Integer
Private two, three, four, five, six, seven, eight, nine, ten,
eleven, twelve As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim objRN As Random = New Random
dice1 = objRN.Next(1, 7)
dice2 = objRN.Next(1, 7)
Label1.Text = dice1
Label3.Text = dice2
CountDice(dice1, dice2)
End Sub
Sub CountDice(ByVal x As Integer, ByVal y As Integer)
If (x + y) = 2 Then
two = two + 1
2. ElseIf (x + y) = 3 Then
three = three + 1
ElseIf (x + y) = 4 Then
four = four + 1
ElseIf (x + y) = 5 Then
five = five + 1
ElseIf (x + y) = 6 Then
six = six + 1
ElseIf (x + y) = 7 Then
seven = seven + 1
ElseIf (x + y) = 8 Then
eight = eight + 1
ElseIf (x + y) = 9 Then
nine = nine + 1
ElseIf (x + y) = 10 Then
ten = ten + 1
ElseIf (x + y) = 11 Then
eleven = eleven + 1
Else
twelve = twelve + 1
End If
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
ListBox1.Items.Clear()
ListBox1.Items.Add(" Value Count")
ListBox1.Items.Add(" ---------- -----------")
ListBox1.Items.Add(" ")
ListBox1.Items.Add(" 2 " & two)
ListBox1.Items.Add(" 3 " & three)
ListBox1.Items.Add(" 4 " & four)
ListBox1.Items.Add(" 5 " & five)
ListBox1.Items.Add(" 6 " & six)
ListBox1.Items.Add(" 7 " & seven)
ListBox1.Items.Add(" 8 " & eight)
ListBox1.Items.Add(" 9 " & nine)
ListBox1.Items.Add(" 10 " & ten)
ListBox1.Items.Add(" 11 " & eleven)
ListBox1.Items.Add(" 12 " & twelve)
End Sub
End Class