Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# how determine highest number VBScript

Posted on 2003-03-26
Medium Priority
5,342 Views
Hi guys,

I have five variables with integer values I need to select just one which has highest value, how to do that?

0

LVL 34

Expert Comment

ID: 8214690
Dim HighestValue

highestvalue=0

If HighestValue < Value1 Then
HighestValue = Value1
End If
If HighestValue < Value2 Then
HighestValue = Value2
End If

If HighestValue < Value3 Then
HighestValue = Value3
End If
If HighestValue < Value4 Then
HighestValue = Value4
End If
If HighestValue < Value5 Then
HighestValue = Value5
End If

Brett
0

LVL 3

Accepted Solution

AmericanDogma earned 200 total points
ID: 8214757
Here is the way I would do it:

<%
' declare variables
DIM aryValue(5)
DIM numHighValue

' intialize variables
numHighValue = 0
aryValue(0) = 5
aryValue(1) = 8
aryValue(2) = 14
aryValue(3) = 12
aryValue(4) = 1

'loop through array and then wriet the highest to the screen
FOR I = LBound(aryValue) TO UBound(aryValue)
IF aryValue(I) > numHighValue THEN
numHighValue = aryValue(I)
END IF
NEXT

response.write numHighValue
%>
0

LVL 1

Expert Comment

ID: 8214783
you could use a lil recursive-magic...

function getHigh(byval myVal1 as integer, byval myVal2 as integer) as integer
if myVal1 > myVal2 then
getHigh = myVal1
else
getHigh = myVal2
end if
end function

and to use this function, I would do:

dim my5values as string
dim myTempArray as variant
dim i as byte, highest as integer

my5values = "4,7,22,3,66,5"
myTempArray = split(my5values, ",")

for i = 0 to ubound(myTempArray) - 1
highest = getHigh(highest, myTempArray(i))
next i

You may need to debug it a lil because I didn't test it in VB. The concept definately works thou. Hope it helps...

Cheers,
-prisca-
0

Author Comment

ID: 8214822
Thank you guys!!!!!!!!!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…