' Snakeeyes Example ' Simulate rolls of two fair dice. ' Count how many rolls are needed to obtain snakeeyes (pair of ones). Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents txtNumRolls As System.Windows.Forms.TextBox Friend WithEvents btnNewSimulation As System.Windows.Forms.Button Private Sub InitializeComponent() Me.txtNumRolls = New System.Windows.Forms.TextBox Me.btnNewSimulation = New System.Windows.Forms.Button Me.SuspendLayout() ' 'txtNumRolls ' Me.txtNumRolls.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtNumRolls.Location = New System.Drawing.Point(24, 16) Me.txtNumRolls.Name = "txtNumRolls" Me.txtNumRolls.Size = New System.Drawing.Size(240, 29) Me.txtNumRolls.TabIndex = 0 Me.txtNumRolls.Text = "" ' 'btnNewSimulation ' Me.btnNewSimulation.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnNewSimulation.Location = New System.Drawing.Point(24, 64) Me.btnNewSimulation.Name = "btnNewSimulation" Me.btnNewSimulation.Size = New System.Drawing.Size(240, 40) Me.btnNewSimulation.TabIndex = 1 Me.btnNewSimulation.Text = "New Simulation" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 126) Me.Controls.Add(Me.btnNewSimulation) Me.Controls.Add(Me.txtNumRolls) Me.Name = "Form1" Me.Text = "SnakeEyes Example" Me.ResumeLayout(False) End Sub #End Region Private Sub btnNewSimulation_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnNewSimulation.Click Dim r As New Random Dim count, die1, die2 As Integer count = 0 Do die1 = r.Next(1, 7) die2 = r.Next(1, 7) count += 1 Loop Until die1 = 1 And die2 = 1 txtNumRolls.Text = count End Sub End Class