Navigation:  ThinBASIC language > Script structure >

TBMain

Previous pageReturn to chapter overviewNext page

 

Default main function

 

thinBasic implements a not mandatory "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.

 

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