Start from a main routine: Difference between revisions

From Rosetta Code
Content added Content deleted
({{header|ZX Spectrum Basic}})
m ({{omit from|Brlcad}})
Line 55: Line 55:


{{omit from|Bc|Scripts start running from the top}}
{{omit from|Bc|Scripts start running from the top}}
{{omit from|Brlcad|Scripts start running from the top in mged}}
{{omit from|C}}
{{omit from|C}}
{{omit from|C++}}
{{omit from|C++}}

Revision as of 11:15, 12 July 2011

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.

AWK

The awk language is data driven. However, it does support the use of begin blocks, so we could use one of those to provide us with a main startup procedure:

<lang awk>BEGIN {

 # This is our main startup procedure
 print "Hello World!"

}</lang>

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 called MMain.bas
  • 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 MMain.bas is selected, by clicking in the list
  • From the pulldown list, choose "Sub Main"
  • Click the OK button.

ZX Spectrum Basic

On the ZX Spectrum, there is no main function as such. However a saved program can be made to start running from a particular line number by providing the line number as a parameter to the save command. The following example will save the program in memory so that it starts running from line 500:

<lang zxbasic>SAVE "MYPROG" LINE 500: REM For a program with main code starting at line 500</lang>