Advanced function definitionsMenu

Applies to:Fast Math Parser
Powerful function definitions with overloading, bootstrapping, callbacks, etc.
Remarks
Sometimes a simple function just won't do. uCalc lets you define many kinds of advanced functions depending on what you're trying to accomplish. Here's an overview. The reference section of the help file has more details on each kind of function: ## Optional parameters To define optional parameters, simply tack on a "=" followed by a default value. #c uc.DefnineFunction("Area(Length, Width = 20)") Answer = uc.Eval("Area(10)") ' Returns: 200 Answer = uc.Eval("Area(10, 5)") ' Returns: 50 #c ## Function Overloading This simply means that you can use the same name to define several different functions, as long as they have a different number of parameters, or the they parameters don't match the same data type. #c uc.DefineFunction("Area(Length) = x * x") uc.DefineFunction("Area(Length, Width) = Length * Width") uc.DefineFunction("Area(x As String, y As String) As String = x+' times '+y+' is '+EvalStr(x+'*'+y)"); Answer = uc.Eval("Area(10)") ' Returns: 100 Answer = uc.Eval("Area(10, 20)") ' Returns: 200 Answer = uc.EvalStr("Area('10', '20')") ' Returns: 10 times 20 is 200 #c ## Variable number of parameters #c uc.DefineFunction("Sum(x ...) = For(x, 1, ArgCount(), 1, Total = Total + Arg(x)); Total #c Here is an oververview of some of the types of functions you can define with uCalc. ##
Prev | Next