Speed Speed Speed - Find Lowest/Highest

Speed Speed Speed - Find Lowest/Highest

Post by Webbi » Sat, 27 Jun 2009 06:51:03

Here's another in the 'Speed-em-up' or 'E-Fish-N-Sea' category.

There is a need to find the Max and Min value within an array of

I wrote a routine to deal with this.

Public Sub GetMinMax(arrLongs() As Long, arrMinMax() As Long)
'arrLongs() is the array of Longs being tested.
'arrMinMax() is used to pass back the results. Index 0 for Min, 1 for

Dim x As Long
Dim lngHighest As Long
Dim lngLowest As Long

lngHighest = 0
lngLowest = 2147483647

For x = 0 To UBound(arrLongs)
If arrLongs(x) > lngHighest Then: lngHighest = arrLongs(x)
If arrLongs(x) < lngLowest Then: lngLowest = arrLongs(x)
Next x

arrMinMax(0) = lngLowest
arrMinMax(1) = lngHighest

End Sub

The idea here is to solve for Min and Max within the same loop rather
than writing two separate routines, one for Min and one for Max, so
that the loop only need to be run through once.

Are there any tricks or suggestions that anyone might have that would
perform better than this?

Assume that the array of Longs sent to this routine is HUGH.



Speed Speed Speed - Find Lowest/Highest

Post by Webbi » Sat, 27 Jun 2009 08:47:36

n Thu, 25 Jun 2009 17:52:20 -0500, dpb < XXXX@XXXXX.COM > wrote:

You're kidding, right?...right?

Been using it since introduced to Basic around 1978.

Old habit.

Okay. The plan wasn't reusability, but suggestion well taken.

If not, the lngLowest will simply equal 0 which would be correct.

Doesn't this only change the initialize values for these two
variables? Does it actually change anything in speed or results? If
there is a zero in the bunch, lngLowest will still equal 0.

I suppose it saves 1 revolution of the loop. :-)
I'll make the modification.

Most definitely.

No, not sorted. If so, I'd be able to take the first and last array
item as the lowest and highest value. Sorting it would make this task
take much longer, and I do need the values in the order they currently
are for display reasons.

Each array index, from 0 to UBound, relates directly to the grid that
will display those values. Column 0 will display value at index 0 of
the array, etc. So the order must remain as is.

The values for each array item is the result of adding up 'points'.
And yes, I can in fact add the Lowest/Highest variables within the
loop that does the point adding and array fill. However, I was
interested in seeing how this function itself can be improved on
rather than tricking out my code. But hey, you did just give me a
short-cut I was not thinking about outside of this thread. Thanks!

Huge. LOL!

Hey, what are you, my English teacher or a stand-up comedian? :-) Or
are you bragging of knowing Hefner? LOL!

Thanks amigo.



Speed Speed Speed - Find Lowest/Highest

Post by Webbi » Sat, 27 Jun 2009 11:18:46

n Thu, 25 Jun 2009 19:28:46 -0500, dpb < XXXX@XXXXX.COM > wrote:

Actually, I started out programming Cobol back in 73, and learned
Fortran during a 6-month stint in community college in 76. Between
that was RPG-I and RPG-II, Assembly, etc. Basic around 78, C around
mid-80's, C++ in late 80's, Pascal (Delphi) early 90's, then VB3
around that time.

And I don't recall anyone suggesting that I use a particular letter as
my iterator variable. Hmmm. Has my memory really gotten that bad? :-)

But then, you'd think that after learning all these languages that I'd
have hunkered down and become a real programmer. Unfortunately, I was
a computer electronics technician most of my career, so programming
was just something I used infrequently or dabbled with out of
curiousity. Oh, and it did come in use for troubleshooting systems
from time to time.

But no, I still don't recall reading or being taught that about
iterator variables.

You really are pulling my leg, aren't you?


Speed Speed Speed - Find Lowest/Highest

Post by Bob Butle » Sun, 12 Jul 2009 03:41:35

Actually I-N (the first 2 letters of INteger)

and I use x,y,z as loop variables partly because I learned Fortran after
Basic so the habit was already ingrained...

Speed Speed Speed - Find Lowest/Highest

Post by Bob Butle » Sun, 12 Jul 2009 05:58:25


Texts? I don't read no stinkin' texts! <g>