Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I find the smallest # from a series #s

Status
Not open for further replies.

Mtlca401

Programmer
Mar 18, 2003
42
US
I have 3 strings with 3 different numbers in them. Is there some way to find out which of those strings has the smallest number?
 
Try converting them to Long integers and making a comparison.

Code:
CLng([i]String1[/i])

Now a switch function statement will return the smallest value:

Code:
Switch(CLng([i]String1[/i]) < CLng([i]String2[/i]) and CLng([i]String1[/i]) < CLng([i]String3[/i]), [i][blue]String1[/blue][/i], CLng([i]String2[/i]) < CLng([i]String3[/i]), [i][blue]String2[/blue][/i], True, [i][blue]String3[/blue][/i])

This function will convert all three and make the comparisons and return the smallest of the three.

Post back if you have any questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Ok cool that worked. I also did it backwards to get the highest, but what about the middle number?
 
Try this code:

Code:
Dim vHighest as string
Dim vLowest as string
Dim vMiddle as string

vLowest = Switch( . . . .
vHighest = Switch( . . . .
vMiddle = Switch(CLng(String1) < CLng(String2) and CLng(String1) > CLng(String3), String1, CLng(String2) < CLng(String3), String2, True, String3)

Substitute the code for the lowest and highest that you already have and then use the last one as indicated above.

Good luck with your project.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
There are functions posted in these fora (basMin; basMax | basMinVal; basMaxVal) which are some what more generic for the extremes, although they do not apply to the "middle" value. The generic name for that (the "Middle" value) would be Median, which is also posted somewhere in these (e.g. Tek-Tips) fora as an independent (seperate) function (basMedian).

For the simplistic case of the few to several values scriverb's code is, perhaps somewhat easier.




MichaelRed
mlred@verizon.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top