|
-
Oct 20th, 2011, 12:21 PM
#1
Thread Starter
New Member
Need help with randomizing program
Hey i am making a program which generates a random number between 1 and 10 and when 7 appears it is suppose to tell you how many tries it took to get the number 7 and then end the application. This is the code I have used:
'Declaration of variables
Dim Number As Integer
Dim Random As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize() 'Randomizes number
End Sub
Private Sub btnNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumber.Click
Do
Number = Int(10 * Rnd() + 1) 'Randomizes the variable
lblNumber.Text = Number 'Displays number in label
Random = Random + 1 'Increases count by an increment of 1
lblRandom.Text = Random 'Displays count in label
Loop Until Number = 7 'End loop when variable is 7
If Number = 7 Then 'If number is 7
Random = 0 'Change value of variable
MsgBox("Congratulations, it took you " & lblRandom.Text & " tries to get the number 7!") 'Displays a message box which displays the number of tries it took you to get the number 7
Application.Exit() 'Closes the appication
End If
End Sub
End Class
This code only generates the number 7 and exits the application, each time i click the random button but i want it to show the other number it randomizes too for example 1 2 3 4 .. etc, if u dont understand, please try it, but im trying to say, when i clikc random it just says number 7 (does randomizing in background) and tells you how much tries it took but i want it to show the other number it randomized also and when 7 appears, then exit the program
PLEASE HELP!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|