Global class
Global is the application’s app object — a singleton that the runtime instantiates on startup and whose members are accessible from any code in the project without qualification. Writing App.Path is in fact a call to Global.App.Path; the leading Global. is implicit. The class exists so that the language’s built-in globals — the singletons App, Clipboard, and Screen, the Forms collection, the Printer and Printers objects, the resource loaders, and the Load / Unload form-lifetime helpers — can be reached uniformly through the same name resolution path.
There is exactly one Global per process and it is not creatable from user code: no New Global, no public coclass to instantiate. The runtime publishes it via the IDE’s special [AppObject] mechanism, and the compiler maps unqualified references to its members.
' All four of these resolve to a method/property on Global:
Dim p As StdPicture
Set p = LoadPicture(App.Path & "\splash.png")
Form2.Show
Load Form3 ' creates the form without showing it
Unload Form1
- Built-in singletons
- Forms collection
- Resource loaders
- Form lifetime helpers
- Printer and Printers
- Properties
- Methods
Built-in singletons
App, Clipboard, and Screen return the corresponding runtime singletons. Each is documented on its own page:
- App — application metadata, version info, and process state.
- Clipboard — system clipboard access.
- Screen — primary-display metrics, active form/control, application-wide mouse pointer.
These properties are cached references — repeated reads return the same object instance for the lifetime of the process.
Forms collection
Forms returns the application’s collection of currently-loaded Form instances — every form that has been Load-ed or Show-n but not yet Unload-ed. The collection is live: it grows when a form is loaded and shrinks when one is unloaded. The collection supports three operations:
- Forms.Count — a Long giving the number of currently-loaded forms.
- Forms.Item( Index ) — the Form at zero-based Index. Item is the default member, so
Forms(0)andForms.Item(0)are equivalent. Reading a negative or out-of-range index raises run-time error 9 (Subscript out of range). - Forms.Add( Name ) — creates a new instance of the form class named Name, adds it to the collection, and returns the new Form. The form is loaded but not shown.
The collection also supports For Each enumeration:
Dim f As Form
For Each f In Forms
Debug.Print f.Name, f.Caption
Next
A common idiom is closing every open form at shutdown — note that unloading shrinks the collection, so iterate backwards or by index from the top down:
Dim i As Long
For i = Forms.Count - 1 To 0 Step -1
Unload Forms(i)
Next
Resource loaders
twinBASIC compiles project-level resources (bitmaps, strings, raw byte blobs) into the final EXE’s resource section. The four LoadRes* methods retrieve them at run time:
- LoadResPicture — loads a bitmap, icon, or cursor resource into a StdPicture.
- LoadResString — loads a string resource.
- LoadResData — loads a raw byte-array resource.
- LoadResIdList — enumerates the IDs of resources of a given type.
LoadPicture loads a picture from a file rather than from an embedded resource — typically used at run time for user-chosen content or for resources kept outside the EXE.
Form lifetime helpers
Load creates a form (or, for control arrays, a control instance) without showing it; Unload tears it back down. Both are written without parentheses by convention — Load Form1, Unload Form1 — and behave as statements, but they are in fact calls to Global.Load and Global.Unload. The corresponding form-lifecycle events (Initialize, Load, Unload, Terminate) fire at the expected points.
Printer and Printers
The compile-time FEATURE_PRINTER flag exposes the Printer and Printers members. Printer is the currently-selected printer, and Printers is the collection of all installed printers; assigning a different printer object to Printer switches the application’s current printer.
Properties
App
The application’s singleton App instance — its identity, version, and process-state metadata. Read-only.
Clipboard
The application’s singleton Clipboard instance — the system clipboard wrapper. Read-only.
Forms
The application’s live collection of currently-loaded Form instances. Read-only. See Forms collection.
Printer
The currently-selected Printer. Readable and assignable with Set — assigning a different printer object switches the application’s current printer.
Printers
The Printers collection of all installed printers on the system. Read-only.
Screen
The application’s singleton Screen instance — primary-display metrics, active form/control, application-wide mouse pointer. Read-only.
Methods
Load
Creates an instance of the named form (or a new element of a control array) without showing it. The form’s Initialize and Load events fire.
Syntax: Load object
- object
- required The default instance of a form class (
Form1), an explicit form reference, or a control-array element (Command1(3)).
Load Form2 ' instantiates and runs Form_Load, but Form2 stays hidden
Set frm = Forms("Form2") ' the new instance now exists in Forms
LoadPicture
Loads a picture from a file. Returns a stdole.IPictureDisp.
Syntax: LoadPicture( [ FileName [, Size [, ColorDepth [, X [, Y ] ] ] ] ] )
- FileName
- optional A String giving the path to a
.bmp,.dib,.gif,.jpg,.png,.wmf,.emf,.ico, or.curfile. When omitted, returns an empty picture — useful for clearing an Image or PictureBox’s Picture property. - Size
- optional A member of LoadPictureSizeConstants — meaningful only for icons and cursors, where it picks among the sizes stored in the file.
- ColorDepth
- optional A member of LoadPictureColorConstants — meaningful only for icons and cursors, where it picks among the colour depths stored in the file.
- X, Y
- optional Width and height overrides used when Size is vbLPCustom, in pixels.
Set imgLogo.Picture = LoadPicture(App.Path & "\logo.png")
Set imgLogo.Picture = LoadPicture() ' clears the picture
LoadResData
Loads a raw resource — usually a binary blob — from the application’s resource section, as a Byte() array wrapped in a Variant.
Syntax: LoadResData( id, Type )
- id
- required The resource ID, either as a Long (numeric ID) or String (name).
- Type
- required The resource type, identifying the resource section to look in. Either a Long standard-resource type or a String custom-resource type.
LoadResIdList
Returns the list of resource IDs in the resource section of the given type, as a Variant array.
Syntax: LoadResIdList( Type )
- Type
- required The resource type — see LoadResData.
LoadResPicture
Loads a picture, icon, or cursor resource from the application’s resource section into a stdole.IPictureDisp.
Syntax: LoadResPicture( id, restype [, width [, height ] ] )
- id
- required The resource ID — Long (numeric) or String (name).
- restype
- required A member of LoadResConstants — vbResBitmap, vbResIcon, or vbResCursor.
- width, height
- optional Pixel dimensions for icon/cursor resources; 0 (default) selects the resource’s natural size.
LoadResString
Loads a string resource from the application’s resource section. Returns a String.
Syntax: LoadResString( id )
- id
- required The resource ID, as a Long.
Unload
Tears down the form (or removes the control-array element). The form’s QueryUnload, Unload, and Terminate events fire in order. Either of the first two can set its Cancel argument non-zero to veto the unload, in which case the form remains loaded and visible.
Syntax: Unload object
- object
- required The default instance of a form class, an explicit form reference, or a control-array element.
Unload Me ' close the current form
Unload Forms(0) ' close whichever form is at the head of the list