Click to See Complete Forum and Search --> : Simple Problem
james07
Jul 27th, 2001, 03:07 AM
Hey everyone, I know this is probably a simple answer but I am new to VB and this has me stumped. Here is the problem.
You have 4 input Boxes come up. In each box a number is entered. Then the four numbers are compared, and then each number is assinged to a variable from least to greatest, and then a total is assigned to a fifth variable. Like this.
numbers entered: 3,8,5,2
Displayed in 5 labels
A= 2
B= 3
C= 5
D= 8
E= 18
Please Help!
James
Bjwbell
Jul 27th, 2001, 03:34 AM
put four text boxes, one command button and five labels on the
form. Paste this code
int o the form code and thats it.
Private Sub Command1_Click()
Dim A As Double ' declare our varibles
Dim B As Double
Dim C As Double
Dim D As Double
Dim E As Double
Dim temp As Double ' a temp variable to hold values
Dim i As Integer ' the count for the for loop
A = Text1.Text ' assign text1.text to A
B = Text2.Text
C = Text3.Text
D = Text4.Text
E = A + B + C + D ' Add up A B C and too make E
For i = 0 To 3 ' loop 4 times. so that if D is smaller than A goes thrue All the other variable and change place with a
If A > B Then ' A need to be less than D so check and see if it is. If it's not change A to B And B to A
temp = B
B = A
A = temp
End If
If B > C Then 'same as with A
temp = C
C = B
B = temp
End If
If C > D Then ' Smae as with A
temp = D
D = C
C = temp
End If
Next i
Label1.Caption = A ' put the values int the lables
Label2.Caption = B
Label3.Caption = C
Label4.Caption = D
Label5.Caption = E
End Sub
Note i'm sleepy so the comments might not make sense.
james07
Jul 27th, 2001, 03:58 AM
Thanks Bjwbell,
James
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.