MAX Value in Series of numbers

# Thread: MAX Value in Series of numbers

1. Join Date
Dec 1969
Posts
67

## MAX Value in Series of numbers

How do I return the MAX and MIN value respectively of a series of numbers? <BR><BR>i.e. the equivalent of MAX(int1, int2, int2,...)?<BR><BR>Thanks.

2. Senior Member
Join Date
Dec 1969
Posts
1,024

## RE: MAX Value in Series of numbers

Is it a string, db recordset or what?

3. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: MAX Value in Series of numbers

&#060;%<BR>Function ReturnMax(arrValues)<BR> Dim dblMax: dblMax = 0<BR> Dim intCounter<BR> For intCounter = 0 to UBound(arrValues)<BR> if CDbl(arrValues(intCounter)) &#062; dblMax then<BR> dblMax = CDbl(arrValues(intCounter))<BR> end if<BR> Next<BR> ReturnMax = dblMax<BR>End Function<BR>%&#062;<BR><BR>Is it that hard?<BR><BR>Craig.

4. Join Date
Dec 1969
Posts
67

## RE: MAX Value in Series of numbers

The data is 12 field values from a recordset, so I was going to pass them explicitly. <BR><BR>Can I pass these to your function above delmiinated by commas? Eg ReturnMax(int1, int2, in3, ..., int12)?

5. Senior Member
Join Date
Dec 1969
Posts
450

## RE: MAX Value in Series of numbers

if Request.QueryString("level")= "level1" then<BR>Val="1, 2, 3"<BR>X = Split(trim(Val), ", ")<BR>For i = 0 to Ubound(X)<BR>if i = LBound(X) then &#039; this gets the Min<BR> FinalValMin= X(i)<BR>elseif i = UBound(X) then<BR> FinalValMax=X(i) &#039; this gets the Max<BR>end if<BR>next<BR>Response.Write FinalValMin & "&#060;p&#062;" & FinalValMax

6. Senior Member
Join Date
Dec 1969
Posts
16,931

## You're assuming...

...that they are in order already.<BR><BR>Craig.

7. Senior Member
Join Date
Dec 1969
Posts
16,931

## Not EXACTLY, but yeah:

You can use:<BR>&#060;%<BR>intMax = ReturnMax(Array("1","2","3","6","4"))<BR>%&#062;<B R><BR>Craig.

8. Senior Member
Join Date
Dec 1969
Posts
450

## Yes

and by the way get rid of the first line

9. Join Date
Dec 1969
Posts
67

## Thanks, how do I do the MIN?

Thanks, your method is neat and easy to understand, but how do I get the MIN value now?

10. Senior Member
Join Date
Dec 1969
Posts
1,024

## RE: Thanks, how do I do the MIN?

&#060;% <BR>Function ReturnMaxmin(arrValues) <BR> Dim dblMax<BR> Dim dblMin<BR> Dim intCounter<BR><BR> For intCounter = 0 to UBound(arrValues) <BR> if CDbl(arrValues(intCounter)) &#062; dblMax then <BR> dblMax = CDbl(arrValues(intCounter)) <BR> end if<BR> if CDbl(arrValues(intCounter)) &#060; dblMin then <BR> dblMin = CDbl(arrValues(intCounter)) <BR> end if<BR> Next <BR> ReturnMaxmin = dblMax &", " &dblMin<BR>End Function <BR>%&#062;<BR><BR>Will then give you the two values seperated by a comma-space.

#### Posting Permissions

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