Ask Experts Questions for FREE Help!
Answer   ||    Advanced Search    ||    Help
Ask your question or search...
Login with Facebook
User Name 
Password 
Forgot password? 

Want to become a member? It's free and once you join you can ask and answer questions. Join Now!

Home > Computers & Technology > Programming > Compiled Languages > Visual Basic   »   Random numbers , variable arrays

Question
 
 
#1  
Old Oct 26, 2008, 08:38 PM
bindizzle
New Member
bindizzle is offline
 
Join Date: Oct 2008
Posts: 7
bindizzle See this member's comment history on his/her Profile page.
Random numbers , variable arrays

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 begginer so i need code.

Reply With Quote
 
     

Answers
 
 
Old Oct 28, 2008, 12:34 PM   #2  
Junior Member
satswid is offline
 
Join Date: Oct 2008
Posts: 40
satswid See this member's comment history on his/her Profile page.
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 GoTo 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
  Reply With Quote
 
     

Answer this question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Ask your question or search...

 




Similar Threads
generating random numbers
(11 replies)
Variable Overhead efficency variable
(1 replies)
How do you wrie a program using that attatches the random numbers together
(1 replies)
random
(1 replies)


Bookmarks and Sharing
bookmark twitter facebook

Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Search this Thread

Advanced Search




Copyright ©2003 - 2010 - Advizo, LLC
All times are GMT -8. The time now is 02:56 PM.