Find the highest number.

Thread Solved

Join Date: Jun 2007
Posts: 50
Reputation: Prozeen is an unknown quantity at this point 
Solved Threads: 4
Prozeen's Avatar
Prozeen Prozeen is offline Offline
Junior Poster in Training

Find the highest number.

 
0
  #1
Jun 17th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,850
Reputation: sk8ndestroy14 is an unknown quantity at this point 
Solved Threads: 1
sk8ndestroy14's Avatar
sk8ndestroy14 sk8ndestroy14 is offline Offline
Posting Virtuoso

Re: Find the highest number.

 
0
  #2
Jun 17th, 2007
Edit. Sorry, I thought I could help but I misunderstood the question. I don't know how to delete posts.
Last edited by sk8ndestroy14; Jun 17th, 2007 at 5:12 pm.
Disclaimer: Nothing I say can be considered credible information (I wonder what that means about this disclaimer then).
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 31
Reputation: SkinHead is an unknown quantity at this point 
Solved Threads: 2
SkinHead SkinHead is offline Offline
Light Poster

Re: Find the highest number.

 
0
  #3
Jun 17th, 2007
You're Having A Laugh.....Surely !

If You Really..REALLY Don't Know How To Do This, Then Send Info On :

1. Why It Appears You're Using Dynamically Generated Labels
2. Where The Integer Assignements Come From (Random !, Database etc)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 50
Reputation: Prozeen is an unknown quantity at this point 
Solved Threads: 4
Prozeen's Avatar
Prozeen Prozeen is offline Offline
Junior Poster in Training

Re: Find the highest number.

 
0
  #4
Jun 18th, 2007
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.)
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Find the highest number.

 
0
  #5
Jun 18th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 50
Reputation: Prozeen is an unknown quantity at this point 
Solved Threads: 4
Prozeen's Avatar
Prozeen Prozeen is offline Offline
Junior Poster in Training

Re: Find the highest number.

 
0
  #6
Jun 18th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 31
Reputation: SkinHead is an unknown quantity at this point 
Solved Threads: 2
SkinHead SkinHead is offline Offline
Light Poster

Re: Find the highest number.

 
0
  #7
Jun 18th, 2007
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Function MaxLabel ( Optional nLoopMax as Integer = -1 ) as Long
  2. Dim lMax as Long
  3. Dim lValue as Long
  4. Dim nLoop as Integer
  5.  
  6. If nLoop = -1 Then
  7. nLoopMax = 9
  8.  
  9. For nLoop = 0 to nLoopMax
  10. lVal = Val(Labels(nLoop).Caption)
  11. if (lVal > lMax) Then
  12. lMax = lVal
  13. Next nLoop
  14.  
  15. 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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 50
Reputation: Prozeen is an unknown quantity at this point 
Solved Threads: 4
Prozeen's Avatar
Prozeen Prozeen is offline Offline
Junior Poster in Training

Re: Find the highest number.

 
0
  #8
Jun 18th, 2007
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)
  1. '3rd - 10th labels.
  2. yy = 1
  3. Do
  4. Do
  5. zz = Int((maxm - 1 + 1) * Rnd + 1)
  6. If zz <> lbls(yy).Caption Then 'yy = 1-8.
  7. lbls(yy + 1).Caption = zz 'yy = 2-9.
  8. Exit Do
  9. Else
  10. End If
  11. Loop Until lbls(yy + 1).Caption <> "" 'yy = 2-9.
  12. For xyz = 1 To yy + 1 'yy = 1 to 9.
  13. If lbls(xyz).Caption > myval Then
  14. myval = lbls(xyz).Caption
  15. End If
  16. Next xyz
  17. maxm = myval + 1
  18. yy = yy + 1
  19. Loop Until yy = 9
  20. MsgBox "The next highest value is = " & maxm
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC