Start from a main routine

From Rosetta Code
Start from a main routine is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Some languages (like gambas and visual basic) support two startup modes. Applications written on these platforms start with an open window that waits for events, and it is necessary to do some jiggerypokery to cause a main procedure to run instead.

The task is to demonstrate the steps involved in causing the application to run a main procedure, rather than an event driven window at startup.

Languages that always run from main() can be omitted from this task.

Gambas

In gambas, to make an application startup from a main routine:

  • Create a new module called MMain
  • In the MMain module, create a public sub called Main as follows:

<lang gambas>PUBLIC SUB Main()

  ' This is the start of the program
END</lang>
  • Right click the MMain module, then select Startup class from the context menu

Visual Basic

In Visual Basic to make an application startup from a main routine:

  • Create a new module (This will be called Module1.bas by default, but this can be renamed, if desired.)
  • Create a new subroutine in the new module as follows:

<lang vb>SUB Main ()

  ' This is the start of the program
END</lang>
  • From the menu in the application development environment, choose: File, Project Options.
  • Ensure that Module1.bas is selected, by clicking in the list
  • From the pulldown list, choose "Sub Main"
  • Click the OK button.