|
In the last example was introduced a variable "I" In order to use the variables inside the functions, they have to be declared. It is necessary tell the interpreter that they exist and also of what type they are.
To declare a variable inside a function the following syntax is used:
Dim "variable name 1" As "variable type" = "default", "variable name 2" As "variable type 2" = "default" ...
After the keyword Dim is possible to define more than one variable of the same time, separated by a comma, as shown above.
In particular it has be noted the possibility to assign a default value while declaring. This is called variable initialization. That is only a possibility and it is not mandatory. If you look at the variable "A" in the example above, the variable as not been initialized. Lets see the example updated:
Function MC ( PP As Numeric, UP As Numeric ) As Numeric
Dim I As Numeric = 0, A As Numeric, S As String = "M"
I = UP - PP + 1
Return CalcMove(Close, I)
EndFunction
More than one Dim declaration lines can exist. The example above can also be written as follows:
Function MC ( PP As Numeric, UP As Numeric ) As Numeric
Dim I As Numeric = 0 Dim A As Numeric Dim S As String = "M"
I = UP - PP + 1
Return CalcMove(Close, I)
EndFunction
The Argument Name or the variable name as to be unique inside a function, and cannot be equal to any keyword of this programming language.
|