|
In the programming language, exists a special function. It should be considered as the mother of all the other functions. We are talking about the function Main.
As indicated from its name, this is the main function, it is where the command interpreter will start to execute the code. Having said that, it is superfluous to say that it must be always present, for the code to be executed. There be very careful: there cannot be two Main Functions in the same module.
The function Main have a different syntax from other functions:
Function Main()
There are only the keyword Function and the keyword Main which in this case is also the name of the function. There are no arguments (they would not make any sense), and also the function data type declaration ,for the returned value, is missing. The reason for that is very simple: The data type of the function Main depends from the context. In general it will be either a number or a Boolean value.
Lets see the example updated:
Function Main() Dim MyNum As Numeric 'calling function MC to calculate the close average 'from period 1 to 10 MyNum = MC (1, 10) Return MyNum EndFunction
Function MC ( PP As Numeric, UP As Numeric ) As Numeric 'this function calculate the average close from PP to UP Dim I As Numeric = 0 ' here the default value is 0 Dim A As Numeric = 0 Dim S As String = "M" I = UP - PP + 1 Return CalcMove(Close, I)
EndFunction
As you can see, the function "MC" is called from the function Main. Of course, the calculation here for the function MC is very simple because it is just an example, but it could be much more complex.
|