Program Entry Point
All ViviFire programs must contain one module that starts with
Program and a name.
This module is where your program starts execution.
The name of the program can be the same as one procedure.
When you write
= before the name, then that procedure becomes where the program starts execution.
= is not given, then execution starts at the top of the module.
A procedure lets you easily get arguments from the command line, and/or return an error code to the operating system.
But if these are not necessary in your program, you can select not to use a procedure.
There are alternatives you can use.
Exit Program can return an error code.
Declaration of the procedure
There are four different mixtures of parameters and return types. It can have one parameter or none, and it can return a value or not.
- The easiest procedure is one that does not have parameters and does not return a value.
Program = NotMuch Sub NotMuch MessageBox "Start of program" MessageBox "End of program" End Sub
- The procedure can return a value of the type
Int. The operating system uses this value as the error code for your program. Other programs can read this value.
Program = ErrorOnly Sub ErrorOnly As Int MessageBox "Start of program" ErrorOnly = %EXIT_SUCCESS MessageBox "End of program with error code " & ErrorOnly & "." End Sub
- The procedure can also have one parameter that is an array of
String. Each item in the array is one of the command-line arguments given to run your program. You can select what to do with different arguments.
Program = ArgsAndError Sub ArgsAndError(args() As String) As Int MessageBox "Start of program" For Each arg In args Begin MessageBox arg & " arg" When DONE ArgsAndError = %EXIT_SUCCESS When NONE ArgsAndError = %EXIT_FAILURE MessageBox "No args!" End For MessageBox "End of program with error code " & ArgsAndError & "." End Sub
- The procedure can also examine the given arguments but not return an error code, as follows.
Program = ArgsOnly Sub ArgsOnly(args() As String) MessageBox "Start of program" For Each arg In args Begin MessageBox arg & " arg" When NONE MessageBox "No args!" End For MessageBox "End of program" End Sub