Home > Archive > Visual Basic > November 2005 > function to get Minimum value
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
function to get Minimum value
|
|
| smart.bug@gmail.com 2005-11-30, 7:55 am |
| hi guys
can anyone plz tell me abt any function available in VB 6.0 which is
equivalent to __min(int a, int b) function in VC ..... __min fuctions
returns the minimum of 2 parameters.
thnx
| |
| J French 2005-11-30, 7:55 am |
| On 30 Nov 2005 02:47:02 -0800, smart.bug@gmail.com wrote:
>hi guys
> can anyone plz tell me abt any function available in VB 6.0 which is
>equivalent to __min(int a, int b) function in VC ..... __min fuctions
>returns the minimum of 2 parameters.
Public Function MinLng( ByVal A As Long, ByVal B As Long ) As Long
MinLng = A
If B < A Then MinLng = B
End Function
| |
| Phill W. 2005-11-30, 7:55 am |
| <smart.bug@gmail.com> wrote in message
news:1133347622.490446.118550@g47g2000cwa.googlegroups.com...
> hi guys
> can anyone plz tell me abt any function available in VB 6.0 which is
> equivalent to __min(int a, int b) function in VC ..... __min fuctions
> returns the minimum of 2 parameters.
Oddly, this isn't built in, but can be done easily enough.
if you wanted to "Min" an entire list of values, you could muck about with
Paramarray arguments, but since you're only interested in /two/ values,
try this :
Function Min( ByVal la1 as Long, ByVal la2 as Long ) as Long
' 'C's "int" datatype being, of course, VB's Long ...
If la1 <= la2 Then
Min = la1
Else
Min = la2
End If
End Function
Or, if you're a fan of 'C's ternary operator, "?" and ":", try VB's
equivalent
thereof :
m = IIf( a <= b, a, b )
HTH,
Phill W.
|
|
|
|
|