Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. Public Class Form1
  2.  
  3. Private Sub btnRollDice_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRollDice.Click
  4. Dim intNumRolls As Integer = Val(Me.txtRolls.Text)
  5.  
  6. Dim intCounts(12) As Integer
  7. Call CountTrials(intNumRolls, intCounts)
  8. Call DisplayRollCounts(intCounts, Me.lstRollsOutcomes)
  9.  
  10. End Sub
  11. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. 'Stimulates intNumRolls rolls of two dice and keeps a count of the
  13. 'outcomes
  14. '
  15. 'pre: intCount() has elements with at least index caluies 2 through 12
  16. 'post: intNumRolls dice rollsl stimulated. Counts of intNumRolls
  17. 'stimulated dice rolls stroed in intCounts()/
  18. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19.  
  20. Sub CountTrials(ByVal intNumRolls As Integer, ByRef intCounts() As Integer)
  21.  
  22. Dim intRollOutcomes As Integer
  23.  
  24. Randomize()
  25. Dim intRoll As Integer
  26. For intRoll = 1 To intNumRolls
  27. intRollOutcomes = (Int(6 * Rnd()) + 1) + (Int(6 * Rnd()) + 1)
  28. intCounts(intRollOutcomes) = intCounts(intRollOutcomes) + 1
  29. Next intRoll
  30.  
  31. End Sub
  32. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. 'Displays the contents of intCounts() in a list box
  34. '
  35. 'pre:intCounts() has elements with at least index values 2 through 12.
  36. 'post: Elements ofintCounts() displayed in alist box
  37. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38.  
  39. Sub DisplayRollCounts(ByRef intCounts() As Integer, ByRef lstList As ListBox)
  40.  
  41. Dim intRollOutcomes As Integer
  42. For intRollOutcomes = 2 To 12
  43. lstList.Items.Add(intRollOutcomes & vbTab & _
  44. intCounts(intRollOutcomes))
  45. Next intRollOutcomes
  46.  
  47. End Sub
  48.  
  49.  
  50. Private Sub txtRolls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRolls.TextChanged
  51.  
  52. Me.lstRollsOutcomes.Items.Clear()
  53.  
  54. End Sub
  55.  
  56. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  57.  
  58. End Sub
  59. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement