Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Max() problem

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Max() problem

    How can I determine the highest value from 3 seperate values from 3 seperate tables.
    a = rs(0)
    b=rd1(0)
    c=rs2(0)

    d = max(a,b,c)

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Since VBScript used in ASP doesn't have a built-in Max function:

    http://home.att.net/~wshvbs/wshMathFunctionsPage.htm
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Maths functions

    Thanks roy, In the end I just used a sorting routine, but what drag, just to return the highets of 3 numbers.
    Im glad to see that Im not the only one hit here
    Daryl

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Why do all that when you only have to do this? It took me 5 minutes to knock together, and handles as many values as you need. Deriving a Min() function from it would take seconds too...! :
    Code:
    Function Max(ValueArray)
    	Dim MaxIndex, N
    	
    	'Initialise Max with the first value
    	Max = ValueArray(0)
    	MaxIndex = UBound(ValueArray)
    	
    	'Only continue if there's more than one value
    	If MaxIndex > 0 Then
    		'And loop through the other values
    		For N = 1 To MaxIndex
    			If ValueArray(N) > Max Then Max = ValueArray(N)
    		Next
    	End If
    End Function
    
    Response.Write Max(Array(-15,17,3,40,-5.25))
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    even easier

    thanks marcus thats nice and easy


  •  

    Posting Permissions

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