Who has the most

# Thread: Who has the most

1. BJD
Junior Member
Join Date
Dec 1969
Posts
22

## Who has the most

My brain has stopped working… Is there a simple way to do this?<BR><BR>I have 5 variables (all integers) <BR>I need to know which one is the largest and disregard any zeros<BR><BR>I would post my code but it is too long and sad… There must be a better way.<BR>Even a look over here dummy would be better then what I am doing right now… <BR>

2. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Jut throw it in an array

and sort the array<BR><BR><BR>

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

## If all you need...

...is the biggest one, you don&#039;t even have to sort the array.<BR><BR>&#060;%<BR>max = someArray(i)<BR>maxindex = 0<BR>For i = 0 TO UBound(someArray)<BR> If someArray(i) &#062; max Then <BR> max = someArray(i)<BR> maxindex = i<BR> End If<BR>Next<BR>%&#062;<BR><BR>MUCH faster than sorting it first.<BR><BR>

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

## By the way...

It&#039;s likely that you might want to write your code so that those 5 integers are *never* individual variables but are instead always simply<BR> someArray(i)<BR><BR><BR>

5. BJD
Junior Member
Join Date
Dec 1969
Posts
22

## RE: If all you need...

Thank you! I knew I had read how to do this somewhere. It’s kind of embarrassing but I knew I was on the wrong track when the function I was writing for this reached 30 lines…<BR><BR>Thanks again.<BR>B.<BR>

#### Posting Permissions

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