Program Entry Point
All ViviFire programs must contain one module that starts with Program
and a name.
This module is where your program starts to run.
The name of the program can be the same as one procedure.
When you write =
before the name, that procedure becomes where the program starts to run.
But, if =
is not given, control 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.
For example, 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
Int32
. The operating system uses this value as the error code for your program. Other programs can read this value.Program = ErrorOnly Sub ErrorOnly As Int32 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 Int32 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