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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Maximum or minimum Value in a data array?

Status
Not open for further replies.

storm75m

Programmer
Apr 18, 2001
81
US
My mind is going in circles trying to figure out the best way to do this. I have a dynamic string array and I need to loop throught the records to find the maximum and mininum value in the array. I know that I need to convert the string to a double or something to do the numeric comparisons, but I'm not sure how I should code to find the min and max. Any help would be greatly appreciated, thanks in advance.
 
storm75:

If your array element for min/max is a text representation of a number, you may not have to convert to numeric.

Having said that, you will need to dimension 2 variables in code, either string, integer or double, depending on what type of data you will be testing.

Initially, set each of the variables equal to the first element in your array. Then in a loop starting with the second element of the array, test that element against both variables, one for greater than, one for less than. If they meet the criteria, set the variables equal to that array element.

If you do need to convert to a numeric type, then set the variable types to integer or double, and test against the CInt() or CDbl() of the array element.

In either case, when the loop ends, one variable will contain the maximum value in the array, the other, the minimum value.

Hope this helps,

Vic
 
Hmmmmmmm,

Actually, a normal comparision works quite nicely with string values. There are some cautionary things about compares of different LENGTH strings, otherwise the relational ops are correct:

? "Mike" > "Michael"
True

? &quot;George&quot; <= &quot;Georgio&quot;
True
? &quot;Bob&quot; = &quot;Bob&quot;
True

? &quot;Robert&quot; <> &quot;Robert&quot;
False

... and other expressions

and, you can get some 'unexpected' results depending on the &quot;case&quot; of characters and your settings (Compare)

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top