Ask Experts Questions for FREE Help !
Ask
    bindizzle's Avatar
    bindizzle Posts: 7, Reputation: 1
    New Member
     
    #1

    Oct 26, 2008, 09:38 PM
    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 beginner so I need code.
    satswid's Avatar
    satswid Posts: 42, Reputation: -2
    Junior Member
     
    #2

    Oct 28, 2008, 01:34 PM

    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Random [ 4 Answers ]

Hey, I've just finished year 12 in australia (a couple of days ago actually) And I've always wondered about american high school... I hear on TV and what not about "softmore's" and "freshmans" What do these terms mean? And are there any more?

Generating random numbers [ 11 Answers ]

Not gernating same number twice in a row

Variable Overhead efficiency variable [ 1 Answers ]

Variable overhead is applied in the basis of standard direct labor-hours. If the direct labor efficiency variance is unfavorable, the variable overhead efficiency variance will be? a Favorable b unfavorable c zero d indeterminable

How do you wrie a program using that attatches the random numbers together [ 1 Answers ]

#include #include #include using namespace std; int main() { int I; srand( (int) time(NULL)); i = rand()%4; int num =


View more questions Search