PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Klaas Holland on June 19, 2017, 12:13:56 PM

Title: Passing Parameters
Post by: Klaas Holland on June 19, 2017, 12:13:56 PM
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?
Title: Re: Passing Parameters
Post by: José Roca on June 19, 2017, 03:01:23 PM
Yes.


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

Title: Re: Passing Parameters
Post by: Klaas Holland on June 19, 2017, 06:51:04 PM
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
Title: Re: Passing Parameters
Post by: José Roca on June 19, 2017, 07:04:19 PM

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")
Title: Re: Passing Parameters
Post by: Klaas Holland on June 20, 2017, 07:44:54 AM
Thanks Jose,
You are a genius.