Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub btnRollDice_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRollDice.Click
- Dim intNumRolls As Integer = Val(Me.txtRolls.Text)
- Dim intCounts(12) As Integer
- Call CountTrials(intNumRolls, intCounts)
- Call DisplayRollCounts(intCounts, Me.lstRollsOutcomes)
- End Sub
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 'Stimulates intNumRolls rolls of two dice and keeps a count of the
- 'outcomes
- '
- 'pre: intCount() has elements with at least index caluies 2 through 12
- 'post: intNumRolls dice rollsl stimulated. Counts of intNumRolls
- 'stimulated dice rolls stroed in intCounts()/
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Sub CountTrials(ByVal intNumRolls As Integer, ByRef intCounts() As Integer)
- Dim intRollOutcomes As Integer
- Randomize()
- Dim intRoll As Integer
- For intRoll = 1 To intNumRolls
- intRollOutcomes = (Int(6 * Rnd()) + 1) + (Int(6 * Rnd()) + 1)
- intCounts(intRollOutcomes) = intCounts(intRollOutcomes) + 1
- Next intRoll
- End Sub
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 'Displays the contents of intCounts() in a list box
- '
- 'pre:intCounts() has elements with at least index values 2 through 12.
- 'post: Elements ofintCounts() displayed in alist box
- '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Sub DisplayRollCounts(ByRef intCounts() As Integer, ByRef lstList As ListBox)
- Dim intRollOutcomes As Integer
- For intRollOutcomes = 2 To 12
- lstList.Items.Add(intRollOutcomes & vbTab & _
- intCounts(intRollOutcomes))
- Next intRollOutcomes
- End Sub
- Private Sub txtRolls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRolls.TextChanged
- Me.lstRollsOutcomes.Items.Clear()
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement