V.B 6.0: Comparing multiple integers

Status
Not open for further replies.

jamie7823

Baseband Member
Messages
61
I just bought a visual basic 6 book. This will be my very first language.

Im in ch 3 of he book and it gives an exercise and wants me to make a script to compare 3 random integers and make it print the smallest and largest of the 3.

X is the largest number of the 3.
y is the smallest of the 3.


is there some way i can compare 1 integer to a list?

this is what i had in mind....

If X>(y,z) then
X=largest
End If

If Y> (x,z) then
Y=largest
End If

If Z>(x,y) then
Z=largest

End If

If X<(y,z) then
X=smallest
End If

If Y< (x,z) then
Y=smallest
End If

If Z<(x,y) then
Z=smallest
End If


Print largest ,"is the largest of the 3 numbers."
Print smallest, " is the smallest of the 3 numbers."


Im aware that my print statement may be out of wack but I'd like to concentrate on the comparisons.

Thank you
 
Try this

Dim L,M,S as Integer
Dim Lt,Mt,St as Boolean
L = Int(Rnd*5)
M = Int(Rnd*5)
S = Int(Rnd*5)

If L > M and L > S Then
Lt = True
End if

IF M > L and M > S Then
Mt = True
End if

If S > L and S > M then
St = True
End if

And so on. :)

Basically use the Same code you used, One set for finding the biggest, one for finding the smallest, but instead of using brackets, use the AND operator.
 
Status
Not open for further replies.
Back
Top Bottom