I'm just curious about this aspect of the CRBasic syntax. Example usage could be:
Sub FormatDateTime(dest As String, currDateTime As String, delimiters As String) ... EndSub
This subroutine takes in an input array, currDateTime, after it's been called with RealTime() i.e., RealTime(currDateTime) and formats it as such: (YYYY#MM#DD$HH%MM%SS) where #,$,% are optional delimiting characters passed as a character-array (String). If delimiters is an omitted argument, then the delimiter characters default to "/@:" or (YYYY/MM/DD@HH:MM:SS)
Yes you can do optional parameters. Here is the description from the help in CRBasic Editor:
Subroutines include the ability to pass in optional arguments. These optional parameters are preceded by the Optional keyword. Optional parameters must be intitialized using a constant value (required parameters cannot be initialized). The default for an optional parameter is used by passing in a comma; multiple default parameters are specified using multiple commas. Required parameters cannot follow optional parameters in the definition of the function.
Hi,
I attempted to write an example utilizing optional arguments (since no example is provided in the "Help" directory).
Public PTemp, batt_volt Public Str1 As String * 20 DataTable (Test,1,-1) Minimum (1,batt_volt,FP2,0,False) Sample (1,PTemp,FP2) ' Sample (1,Str1,String) EndTable Sub Routine1(Optional arg1 As String = "DEFAULT")
' Public arg1 As String * 20 = "DEFAULT" 'Incorrect Str1 = arg1 EndSub 'Main Program BeginProg Scan (1,Sec,0,0) PanelTemp (PTemp,250) Battery (Batt_volt) Routine1("Example1") Routine1() CallTable Test NextScan EndProg
I wanted to verify that the optional arguments are initialized in the parameter list, as I have done.
How is it done if the routine were to accept an optional 1 (or 2) dimensional array?