|
-
Nov 26th, 2008, 07:03 PM
#1
Thread Starter
Junior Member
Max Value
Hey guys, new to the forums and new to visual basic
only been on visual basic for about 3 days now and im
stuck finding the highest value I've tryed a
few ways but It seems that it doesnt like to include
"Input2" and "input3" for example if I put
3 in Input 1
2 in Input 2
4 in Input 3
It will show 3 as the highest input and not 4 :/
anyways guys here is the code thanks in advanced
Private Sub Command1_Click()
Dim Max As Long
Dim Sum As Long
Sum = Val(input1.Text) + (input2.Text) + (input3.Text)
Label4.Caption = Sum
If Val(input1.Text) > Val(input2.Text) Then
Max = input1.Text
ElseIf Val(input1.Text) > Val(input3.Text) Then
Max = input1.Text
ElseIf Val(input3.Text) > Val(input1.Text) Then
Max = input3.Text
ElseIf Val(input2.Text) > Val(input1.Text) Then
Max = input2.Text
ElseIf Val(input2.Text) > Val(input3.Text) Then
Max = input2.Text
End If
Label5.Caption = Max
End Sub
-
Nov 26th, 2008, 07:49 PM
#2
Re: Max Value
Instead of comparing the textboxes with each other, how about comparing them with the highest value so far...
-
Nov 26th, 2008, 07:50 PM
#3
Thread Starter
Junior Member
Re: Max Value
Ermm anychance of explaing how? I'm quiet new to VB
-
Nov 26th, 2008, 08:02 PM
#4
Re: Max Value
It sounds too much like homework for me to post any code, sorry. Look at what you have, using ElseIf won't work you need to use separate If's for each comparison. You also only need to make 2 comparisons (if x > y...) to determine the highest out of 3 values.
-
Nov 26th, 2008, 08:38 PM
#5
Re: Max Value
Code:
Max = Val(input1.Text)
If Val(input2.Text) > Max Then Max = Val(input2.Text)
If Val(input3.Text) > Max Then Max = Val(input3.Text)
Label5.Caption = Max
-
Nov 26th, 2008, 09:02 PM
#6
Re: Max Value
 Originally Posted by anhn
Code:
Max = Val(input1.Text)
If Val(input2.Text) > Max Then Max = Val(input2.Text)
If Val(input3.Text) > Max Then Max = Val(input3.Text)
Label5.Caption = Max
When in doubt, AnHn delivers.
The highest value is always the first value that arrives until another one arrives that exceeds it.
The lowest value is always the first value that arrives until another one arrives that undercuts it.
-
Nov 27th, 2008, 09:45 AM
#7
Thread Starter
Junior Member
Re: Max Value
Thanks for the code man worked great
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|