Find the highest number.
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.
Prozeen
Junior Poster in Training
52 posts since Jun 2007
Reputation Points: 10
Solved Threads: 4
Edit. Sorry, I thought I could help but I misunderstood the question. I don't know how to delete posts.
sk8ndestroy14
Posting Virtuoso
1,852 posts since Mar 2007
Reputation Points: 437
Solved Threads: 1
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.)
Prozeen
Junior Poster in Training
52 posts since Jun 2007
Reputation Points: 10
Solved Threads: 4
Thanks QVeen72.
I tried your suggestion and it now works. Previously, I was trying to find the highest number "on the go" without setting it aside (i.e. MyVal) to compare it to the other integers.
Thanks once again.
Prozeen
Junior Poster in Training
52 posts since Jun 2007
Reputation Points: 10
Solved Threads: 4
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.
'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
Prozeen
Junior Poster in Training
52 posts since Jun 2007
Reputation Points: 10
Solved Threads: 4