?
Solved

how determine highest number VBScript

Posted on 2003-03-26
4
Medium Priority
?
4,750 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

801 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