A constructor is a method (sub or function) that is executed when an object is initialized.
' Gambas class file X AS StringA variable has to be global in order for it to be visible in different methods (_new() and Button1_Click()). See How to use local and global variables.
STATIC PUBLIC SUB Main() DIM hForm AS Fmain hForm = NEW Fmain hForm.Show END PUBLIC SUB _new() X = "cool" END'The constructor is a method, called: PUBLIC SUB _new()
PUBLIC SUB Button1_Click() TextLabel1.Text = "Constructors are " & X & "!" END