CIS 1006

Assignment 3

Due: Thursday, Jan 30

Goal: Gain experience with random numbers and controls in Visual Basic.

Task: For this assignment you must create a simple interface to a video gambling machine.  There should be a large button labeled "Play".  When this button is pressed the computer should randomly display either the number "1", "2", or "3" in each of the three text boxes above the "Play" button.  On the right side of the form there is a scroll bar with the words "Amount Bet" above it.  When the user moves the scroll bar up and down, the dollar amount in the text box below should change between $1 and $10. 

To generate random numbers you must do two things in your code.  At the start of your code put the command Randomize which starts the random number generator.  Now you can use the term Rnd to  represent a random decimal number between 0 and 1 in your code. Finally you can use the function Int() which converts a decimal number to an integer.  Putting this all together you get the following code which displays a random integer between 0 and 9 in the text box named text1: 

Sub Command1_Click() 
    Randomize 
    text1.text = Int(Rnd * 10) 
End Sub

Add a text box to display how much money the player has and start the player with $100. When the player clicks on the "Play" button the three random numbers should be set. If the numbers are all the same, the player should win 10 times their bet otherwise the player should lose what they bet.