[AccessD] highest value of 4 variables - urgent

Kath Pelletti kp at sdsonline.net
Mon Nov 5 15:40:05 CST 2007


that's great John - thanks.


----- Original Message ----- 
From: "jwcolby" <jwcolby at colbyconsulting.com>
To: "'Access Developers discussion and problem solving'" 
<accessd at databaseadvisors.com>
Sent: Sunday, November 04, 2007 11:31 PM
Subject: Re: [AccessD] highest value of 4 variables - urgent


> Probably the easiest way to do this is to turn the set of variables into 
> an
> array of variables.
>
> '.Comments  :
> '.Parameters:
> '.Sets      :
> '.Returns   :
> '.Created by: Colby Consulting
> '.Created   : 11/4/2007 7:27:49 AM
> Function MaxOfVars(ParamArray varValues() As Variant)
> On Error GoTo Err_MaxOfVars
> Dim lvarVal As Variant
> Dim lvarMax As Variant
>    lvarMax = varValues(0)
>    For Each lvarVal In varValues
>        If lvarVal > lvarMax Then
>            lvarMax = lvarVal
>        End If
>    Next lvarVal
>    MaxOfVars = lvarMax
> Exit_MaxOfVars:
> Exit Function
> Err_MaxOfVars:
>    Select Case Err
>    Case 9 'No values passed in.  Return what you want here.  Will
> currently return a null
>   MaxOfVars = null
>        Resume Exit_MaxOfVars
>    Case Else
>        MsgBox Err.Description, , "Error in Function Module1.MaxOfVars"
>        Resume Exit_MaxOfVars
>    End Select
>    Resume 0    '.FOR TROUBLESHOOTING
> End Function
> Then you can simply:
>
> 1) Set the lvarMax = the first value in the array
> 2) Iterate through the array
> 3) Check if lvarVal > lvarMax
> 4) If it is set lvarmax = lvarVal
> 5) When you are done lvarMax is equal to the largest value in the array
> 6) Return lvarMax
>
> 7) if nothing is passed in you hit the error handler with a value of 9 and
> return a null
>
> Now you can pass in any number of values and always get back the max value
> regardless of the number passed in.
>
> BTW, the function is tested and works.
>
> John W. Colby
> Colby Consulting
> www.ColbyConsulting.com
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Kath Pelletti
> Sent: Saturday, November 03, 2007 6:57 PM
> To: Access D Normal List
> Subject: [AccessD] highest value of 4 variables - urgent
>
> maybe i am having a vague moment - but what function can I use to get the
> highest value of 4 variables, eg:
>
>
> eg. I want to know x where x is the highest of (var1, var2, var3, var4)
>
> ta
> ______________________________________
> Kath Pelletti
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 





More information about the AccessD mailing list