Program Structure

Top  Previous  Next

A typical Tibbo Basic source code file (a compilation unit with the .tbs extension) contains the following sections of code:

Include Statement(s)

These are used to include other files from the same project (such as header files [.tbh] containing global variable definitions or utility functions). See:

 

 

include "global.tbh"

 

Global Variables Definitions

Here you define any variables you wish to be accessible throughout the current compilation unit:

 

 

dim foo, bar as integer

 

Subs and Functions

These are procedures which perform specific tasks, and may be called from other places within the project.

 

 

sub foo

...

end sub

 

function bar (a as integer) as byte

...

end function

 

Event Handlers

Tibbo Basic is event-driven. Event handlers are platform-dependent subs, that are executed when something happens. This 'something' depends upon your platform. If your Tibbo Basic program runs on a refrigerator, you would probably have an event handler for the door opening.

 

 

sub on_door_open

       light = 1 ' turn on the light when someone opens the door to your fridge.

end sub

 

 

Just like any other sub, events can have arguments (input parameters):

 

 

sub on_door_state(state as byte)

  ' turn the light on and off as the fridge door gets opened and closed

  if state=0 then

     light=0

  else

     light=1

  end if

end sub

 

 

Event handles are always subs and never functions (i.e. they never return any value as there is nobody to return it to)!