[AccessD] highest value of 4 variables - urgent

Andy Lacey andy at minstersystems.co.uk
Mon Nov 5 06:03:36 CST 2007


Hats off to you JC. Your solution beats mine easy. I'll be using this
principle.

-- Andy Lacey
http://www.minstersystems.co.uk 

> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com 
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
> Sent: 04 November 2007 12:38
> To: 'Access Developers discussion and problem solving'
> Subject: Re: [AccessD] highest value of 4 variables - urgent
> 
> 
> BTW. to test this simply go to the debug window and enter:
> 
> ?MaxOfVars(4,2,5,4,8,4,9,0)
> 
> and hit enter.  
> 
> Place a breakpoint at lvarmax=varvalues(0) and then step if 
> you want to watch it run.
> 
> Next do 
> 
> ?MaxOfVars(5,2,6,7,4)
> 
> Next do 
> 
> ?MaxOfVars()
> 
> 
> 
> 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 jwcolby
> Sent: Sunday, November 04, 2007 7:32 AM
> To: 'Access Developers discussion and problem solving'
> 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
> 
> -- 
> 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