TBMain

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Script structure >

TBMain

 

Default main function

 

thinBasic implements an optional "main function" logic.

If script contains a function called TBMain and during the script execution TBMain was not called by direct invocation, thinBasic will execute TBMain automatically.

 

TBMain is like the "main" function in C programming language.

 

TBMain template is like the following:

 

Function TBMain() As Long

  ...

  Function = <TBMain Return value>

End Function

 

Value returned by TBMain will be used to pass script return code to the calling process or to the operating system.

 

If script uses APP_SetReturnCode, TBMain return code will have an higher priority over it and will be used instead.

 

Using Return statement from inside TBMain, will terminate the script and optionally returning a value propagated to exit code

 

Is TBMain mandatory?

 

No, it is not mandatory. A script can or can not contains a TBMain function. It is up to programmer to use this feature or not.

 

I do not like TBMain name. Can I change it?

 

Yes, you can set up any script function as main function (at anytime during script execution) using APP_SetEntryPoint and APP_GetEntryPoint