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
4
Medium Priority
?
5,342 Views
Last Modified: 2007-11-27
Hi guys,

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

Thanks a lot in advance!
0
Comment
Question by:VadimVadim
4 Comments
 
LVL 34

Expert Comment

by:arbert
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

by:
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

by:babypris
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

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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/…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question