VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Max() Function

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
2112 Views, 2 Replies

Max() Function

Is it possible to find the largest of a group of numbers in Acad VBA similar
to the Excel Max() function?

Best regards,

Dale
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

... nope -- hafta write'em -- (lisp has them -- funny why VBA doesn't):

Syntax for all four functions below:

Minimum(1,2,5,6,3,etc...)
Min(Array)
Maximum(1,2,5,6,3,etc...)
Max(Array)

'================================== watch for word wrap

Public Function Minimum(ParamArray Numbers())
Minimum = Min(Numbers)
End Function

Public Function Maximum(ParamArray Numbers())
Maximum = Max(Numbers)
End Function

'Send back the minimum value from a list of numbers
Public Function Min(ByVal NumericArray As Variant) As Variant
Dim i As Integer
Dim MinVal As Double
Dim CurVal As Double
CurVal = NumericArray(0)
MinVal = CurVal
For i = LBound(NumericArray) + 1 To UBound(NumericArray)
CurVal = NumericArray(i)
If CurVal < MinVal Then MinVal = CurVal
Next
Min = MinVal
End Function

'Send back the maximum value from a list of numbers
Public Function Max(ByVal NumericArray As Variant) As Variant
Dim i As Integer
Dim MaxVal As Double
Dim CurVal As Double
CurVal = NumericArray(0)
MaxVal = CurVal
For i = LBound(NumericArray) + 1 To UBound(NumericArray)
CurVal = NumericArray(i)
If CurVal > MaxVal Then MaxVal = CurVal
Next
Max = MaxVal
End Function
Message 3 of 3
Anonymous
in reply to: Anonymous

Dale and Lanny,

Is this what you are referring to?

Public oExcel As New Excel.Application

Public Sub DoesThisWork()
Debug.Print oExcel.WorksheetFunction.Max(12, 13, 2, 1, 0, 42)
End Sub

Don't forget to set your reference to Excel.

--
Get on the emailing list for notification of the NEW "AutoCAD Visual Basic
Programmers Reference" - the ultimate guide to Visual Basic programming for
R14/2000/2000i
and 2002 by clicking on the link below
mailto:omnisource@worldnet.att.net?subject=NewVBTitle

Joe Sutphin
Author of "AutoCAD 2000 VBA Programmers Reference"
ISBN #1861002564


"Lanny Schiele" wrote in message
news:682BA3B8C4D8F0956B7CF9F65DC6CEDA@in.WebX.maYIadrTaRb...
> ... nope -- hafta write'em -- (lisp has them -- funny why VBA doesn't):
>
> Syntax for all four functions below:
>
> Minimum(1,2,5,6,3,etc...)
> Min(Array)
> Maximum(1,2,5,6,3,etc...)
> Max(Array)
>
> '================================== watch for word wrap
>
> Public Function Minimum(ParamArray Numbers())
> Minimum = Min(Numbers)
> End Function
>
> Public Function Maximum(ParamArray Numbers())
> Maximum = Max(Numbers)
> End Function
>
> 'Send back the minimum value from a list of numbers
> Public Function Min(ByVal NumericArray As Variant) As Variant
> Dim i As Integer
> Dim MinVal As Double
> Dim CurVal As Double
> CurVal = NumericArray(0)
> MinVal = CurVal
> For i = LBound(NumericArray) + 1 To UBound(NumericArray)
> CurVal = NumericArray(i)
> If CurVal < MinVal Then MinVal = CurVal
> Next
> Min = MinVal
> End Function
>
> 'Send back the maximum value from a list of numbers
> Public Function Max(ByVal NumericArray As Variant) As Variant
> Dim i As Integer
> Dim MaxVal As Double
> Dim CurVal As Double
> CurVal = NumericArray(0)
> MaxVal = CurVal
> For i = LBound(NumericArray) + 1 To UBound(NumericArray)
> CurVal = NumericArray(i)
> If CurVal > MaxVal Then MaxVal = CurVal
> Next
> Max = MaxVal
> End Function
>
>
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report