• Welcome to PlanetSquires Forums.
 

Passing Parameters

Started by Klaas Holland, June 19, 2017, 11:43:56 AM

Previous topic - Next topic

Klaas Holland

In CDbl and CLng you can pass both a String expression or a Numeric expression.

Is it possible to create a Function with these possibilities?

If so, how do you do it?

José Roca

Yes.


FUNCTION Foo OVERLOAD (BYVAL x AS DOUBLE) AS LONG
FUNCTION Foo OVERLOAD (BYREF x AS STRING) AS LONG


Klaas Holland

Sorry, but how do I implement this here?

Function EFormat (ByVal nValue as Long) as String

    Dim as String v = Format (nValue/100, "#.00")
   
    Function = v
End Function

José Roca

#3

Function EFormat Overload (ByVal nValue as Long) as String
    Dim as String v = Format (nValue/100, "#.00")
    Function = v
End Function

Function EFormat Overload (ByRef strValue as String) as String
    Dim as String v = Format (Val(strValue)/100, "#.00")
    Function = v
End Function


Usage:

print EFormat(1234)
print EFormat("1234")

Klaas Holland

Thanks Jose,
You are a genius.