min/max math compare func's?

JohnGalt
09-24-2004, 08:40 AM
hello all. I have a really basic question for you: are there any vb functions like min or max so that you might have a bit of code like:

x = min(x+y, 100)

instead of:

x = x+y
if x > 100 then x = 100

peace,

John.

Mike Rosenblum
09-24-2004, 08:43 AM
No, unfortunately not. Pretty surprising, if you ask me...

I have the following in my library of commands:
Function Max2(Input1 As Variant, Input2 As Variant) As Variant
If Input1 > Input2 Then
Max2 = Input1
Else
Max2 = Input2
End If
End Function

Function Max2Dbl(Input1 As Double, Input2 As Double) As Double
If Input1 > Input2 Then
Max2Dbl = Input1
Else
Max2Dbl = Input2
End If
End Function

Function Max2Lng(Input1 As Long, Input2 As Long) As Long
If Input1 > Input2 Then
Max2Lng = Input1
Else
Max2Lng = Input2
End If
End Function

Function Min2(Input1 As Variant, Input2 As Variant) As Variant
If Input1 < Input2 Then
Min2 = Input1
Else
Min2 = Input2
End If
End Function

Function Min2Dbl(Input1 As Double, Input2 As Double) As Double
If Input1 < Input2 Then
Min2Dbl = Input1
Else
Min2Dbl = Input2
End If
End Function

Function Min2Lng(Input1 As Long, Input2 As Long) As Long
If Input1 < Input2 Then
Min2Lng = Input1
Else
Min2Lng = Input2
End If
End Function You can't use Overloading in VB6, so each version needs a slightly different name depending on the Type you are interested in. But, more or less, the above gets the job done...

-- Mike

JohnGalt
09-24-2004, 09:22 AM
No, unfortunately not. Pretty surprising, if you ask me...

I have the following in my library of commands:[vb]
-- Mike

Mike --

Thanks very much. Had checked MSDN for min/max and couldn't find anything. thought surely they exist, just under some other guise. oh well, will just follow your advice and use custom functions.

peace,

John.

Mike Rosenblum
09-24-2004, 09:23 AM
Yeah, I was pretty amazed myself.

They do exist in .Net however. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum