5 variables - determine lowest

# Thread: 5 variables - determine lowest

1. Senior Member
Join Date
Dec 1969
Posts
305

## 5 variables - determine lowest

Is there an easy way to determine the lowest numbered variable our of 5? Its not a recordset but rather a function running 5 seperate times to produce these variables. Now I want to pull out the lowest one.<BR><BR>a = 100<BR>b = 105<BR>c = 110<BR>d = 115<BR>e = 120<BR><BR>I want to get out that a is the smallest.<BR><BR>Any input would be fanatastic - my millions of if statements are getting obnoxious LOL - thanks.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## put into an array

Instead of having <BR> a = someFunction( )<BR> b = someFunction( )<BR> etc.<BR><BR>Do<BR> Dim arr(4)<BR> arr(0) = someFunction( )<BR> ...<BR> arr(4) = someFunction( )<BR><BR>And then dirt simple:<BR> lowestVal = arr(0)<BR> For i = 1 To 4<BR> If arr(i) &#060; lowestVal Then lowestVal = arr(i) <BR> Next<BR><BR>Of, if you need to know *which* is the lowest:<BR> lowestVal = arr(0)<BR> lowest = 0<BR> For i = 1 To 4<BR> If arr(i) &#060; lowestVal Then <BR> lowestVal = arr(i) <BR> lowest = i<BR> End If<BR> Next<BR>

3. Senior Member
Join Date
Dec 1969
Posts
11,334

## Bubble sort

and grab the first/last however you sorted it...examples on 4 guys.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Pardon me, but that's silly...

Why do an ORDER(n-squared) sort when a simple ORDER(n) one-shot loop through the list will work to find the *lowest*.<BR><BR>He never said he needed anything but the lowest.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
305

## RE: Pardon me, but that's silly...

heres the problem though - the variables have to be static - the information I&#039;m using in the functions is static longitude and latitide values coded into the page - rather than pulling 5 different recordsets to get the information.. So in essence I need a way to loop through 5 seperate variables.<BR><BR>I&#039;ve been trying an array and using variable names like str1, str2, str3, but I can&#039;t get it to work..

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Fine...stuff them into the array...

Dim arr(4)<BR>arr(0) = str1<BR>arr(1) = str2<BR>... etc. ...<BR><BR>And then find the lowest.<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Pardon me, but that's silly...

Well, I know he&#039;s doing some sorta zip code distancing, so I figure he may put them in order.<BR><BR>n^2 over 5 records won&#039;t really make a difference.

8. Senior Member
Join Date
Dec 1969
Posts
305

## RE: Fine...stuff them into the array...

there it is! thanks bill

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•