| | |
Find the highest number.
Thread Solved |
Hi all,
I have 3 labels, with 3 captions (i.e. integers)...
Label 1 = 1
Label 2 = 3
Label 3 = 2
What I want to do is search all these labels and find out what the highest number is (in this situation it's 3) so that I can then work out what the next highest value is, for the next label (in the above situation it would be 4.)
Label 4 = 4
Any suggestions?
Thanks.
I have 3 labels, with 3 captions (i.e. integers)...
Label 1 = 1
Label 2 = 3
Label 3 = 2
What I want to do is search all these labels and find out what the highest number is (in this situation it's 3) so that I can then work out what the next highest value is, for the next label (in the above situation it would be 4.)
Label 4 = 4
Any suggestions?
Thanks.
1) There is actually a total of 10 labels in my project.
2) The integers are generated randomly (depending on what the highest and also previous integer is) using VB.
For example, in this program...
The first label will always be a 1.
The second label will always be a 2 (i.e. the next highest number to use, which is not the same as the previous label.)
But the third label could actually be a 1 or a 3 (i.e. not a value that is the same as the previous label.)
2) The integers are generated randomly (depending on what the highest and also previous integer is) using VB.
For example, in this program...
The first label will always be a 1.
The second label will always be a 2 (i.e. the next highest number to use, which is not the same as the previous label.)
But the third label could actually be a 1 or a 3 (i.e. not a value that is the same as the previous label.)
Hi,
Just use mutile "If" conditions :
Dim MyVal As Single
MyVal = Val(Label1.Caption)
If Val(Label2.Caption) > MyVal Then
MyVal = Val(Label2.Caption)
End If
If Val(Label3.Caption) > MyVal Then
MyVal = Val(Label3.Caption)
End If
If Val(Label4.Caption) > MyVal Then
MyVal = Val(Label4.Caption)
End If
Msgox "Highest Value Is : " & MyVal
REgards
Veena
Just use mutile "If" conditions :
Dim MyVal As Single
MyVal = Val(Label1.Caption)
If Val(Label2.Caption) > MyVal Then
MyVal = Val(Label2.Caption)
End If
If Val(Label3.Caption) > MyVal Then
MyVal = Val(Label3.Caption)
End If
If Val(Label4.Caption) > MyVal Then
MyVal = Val(Label4.Caption)
End If
Msgox "Highest Value Is : " & MyVal
REgards
Veena
•
•
Join Date: May 2007
Posts: 31
Reputation:
Solved Threads: 2
If All The Labels Are On The Same Form, Then Use A Control Array Of Labels With Index Values 0 To 9
Then A Loop Will Do The Trick
If You Don't Want To Check All The Labels, Then Pass The Index Of The Last Label In As A Parameter To The Check Function
Then A Loop Will Do The Trick
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Function MaxLabel ( Optional nLoopMax as Integer = -1 ) as Long Dim lMax as Long Dim lValue as Long Dim nLoop as Integer If nLoop = -1 Then nLoopMax = 9 For nLoop = 0 to nLoopMax lVal = Val(Labels(nLoop).Caption) if (lVal > lMax) Then lMax = lVal Next nLoop MaxLabel = lMax
If You Don't Want To Check All The Labels, Then Pass The Index Of The Last Label In As A Parameter To The Check Function
Yes the labels are on the same form and in an array. I also need to check all the labels, so I used the following code. Thanks to everyone for their help.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
'3rd - 10th labels. yy = 1 Do Do zz = Int((maxm - 1 + 1) * Rnd + 1) If zz <> lbls(yy).Caption Then 'yy = 1-8. lbls(yy + 1).Caption = zz 'yy = 2-9. Exit Do Else End If Loop Until lbls(yy + 1).Caption <> "" 'yy = 2-9. For xyz = 1 To yy + 1 'yy = 1 to 9. If lbls(xyz).Caption > myval Then myval = lbls(xyz).Caption End If Next xyz maxm = myval + 1 yy = yy + 1 Loop Until yy = 9 MsgBox "The next highest value is = " & maxm
![]() |
Similar Threads
- My prime Number generator (Python)
- to secomd smallest number in array (Java)
- Please help me find what small errors i have!! (C++)
- calculating sum, average, highest and lowest grades (Visual Basic 4 / 5 / 6)
- Random number with ascending order help (C++)
- Extracting the highest number with C++ (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Everybody, please read this reply to Kali...
- Next Thread: anyone interested in developing open source software
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






