Some functions need arguments in the input. If you do not declare arguments for such a function you can use
#1 to retrieve the first argument in the input,
#2 to retrieve the second argument, and so on. For example:
func FileNameString ()
{
$namestring = #1 + "_" + #2;
return $namestring;
}
func functionName([type name,])
{
[statements]
[return value;]
}
func myfunc(str firstname, str lastname, num age)
{
if (age > 29)
return firstname + " " + lastname;
else
return 0;
}
The arguments declared in the function and variables declared in the function body are local to the scope of the function call. This makes custom functions more portable because there is no risk of overwriting global variables. The function is also more useful as the expected arguments are clearly defined in the function rather than hidden within statements in the function body.
The arguments declared in the function have values that should not be altered in the function, i.e. they should only be read from and not written to. For example, the following function will cause an error:
func myfunc(str firstname, str lastname, num age)
{
clear(firstname);
if (age > 29)
return lastname;
else
return 0;
}
You can still use the #-syntax to read the arguments to a function when argument variables are declared. For example:
func myfunc(str firstname, str lastname, num age)
{
if (age > 29)
return #1 + " " + #2;
else
return 0;
}
func FileNameString(str yourref, str invno)
{
str namestring = yourref + "_" + invno;
return namestring;
}
$nameNumber = FileNameString(&yourReference, &invoiceNumber);
{
str nameNumber = FileNameString(&yourReference, &invoiceNumber);
}
func ChangeDateFormat(str date)
{
str month = date(1,2); //Character 1 and 2 in input string
str day = date(4,2); //Character 4 and 5 in input string
str year = date(7,4); //Character 7 to 10 in input string
str newformat = year + "-" + month + "-" + day;
return newformat;
}
$dateFormatSWE = ChangeDateFormat(&invoiceDate);
{
num dateFormatSWE = ChangeDateFormat(&invoiceDate);
}
func FileNameString()
{
$namestring = #1 + "_" + #2;
return $namestring;
}
$nameNumber = FileNameString(&yourReference, &invoiceNumber);
{
str nameNumber = FileNameString(&yourReference, &invoiceNumber);
}
func ChangeDateFormat()
{
$month = #1(1,2); //Character 1 and 2 in input string
$day = #1(4,2); //Character 4 and 5 in input string
$year = #1(7,4); //Character 7 to 10 in input string
$newformat = $year + "-" + $month + "-" + $day;
return $newformat;
}
$dateFormatSWE = ChangeDateFormat(&invoiceDate);
{
num dateFormatSWE = ChangeDateFormat(&invoiceDate);
}