here is my problem
To create a program that generates 7 random numbers display it in 7 labels (not repeat same number twice)and there a button if u click it picks out the highest number. Im a beginner so I need code.
![]() |
here is my problem
To create a program that generates 7 random numbers display it in 7 labels (not repeat same number twice)and there a button if u click it picks out the highest number. Im a beginner so I need code.
Create a form and place 7 labels and name them from Label1, Label2,. Label7.
Add two buttons
1. Name - cmdGenerate : Caption - Generate
2. Name - cmdHighest : Caption - Highest
Now paste the following code in Code Window
' ************************************************** ***************
' * Module : frmMain
' * Programmer : Khan Shad Mohd.
' * Date : 29 October 2008
' * Copyright : None
' ------------------------------------------------------------------
' * Description : To create a program that
' generates 7 random numbers
' display it in 7 labels (not repeat
' same number twice)and there a
' button if u click it picks out the
' highest number.
' ************************************************** ***************
Private Sub cmdGenerate_Click()
Dim intTemp As Integer
Label1.Caption = GetNextNumber
Label2.Caption = GetNextNumber
Label3.Caption = GetNextNumber
Label4.Caption = GetNextNumber
Label5.Caption = GetNextNumber
Label6.Caption = GetNextNumber
Label7.Caption = GetNextNumber
End Sub
Function GetNextNumber() As Integer
Randomize
Dim intTemp As Integer
Start:
intTemp = Rnd * 10
Dim ctrl As Control
For Each ctrl In Me
If TypeOf ctrl Is Label Then
If Val(ctrl.Caption) = intTemp Then Go to Start
End If
Next
GetNextNumber = intTemp
End Function
Private Sub cmdHighest_Click()
Dim intHighest As Integer
Dim ctrl As Control
For Each ctrl In Me
If TypeOf ctrl Is Label Then
If Val(ctrl.Caption) > intHighest Then intHighest = Val(ctrl.Caption)
End If
Next
MsgBox intHighest
End Sub
All times are GMT -7. The time now is 06:53 AM. |