Liberty BASIC Help Online

GLOBAL var1, var2$...,varN
This statement specifies that the variables listed are global in scope.  They are visible inside functions and subroutines as well as in the main program code.  Global variables can be modified inside functions and subroutines as well, so care must be taken not to alter them accidentally, because this can easily cause errors in the program that are difficult to isolate. Use global variables for things like values for true and false, file paths, user preferences etc.  See also:  Function, Sub
    global true, false, font$
    true = 1
    false = 0
    font$ = "times_new_roman 10"
Special Globals
The special capitalized globals (like WindowWidth, DefaultDir$, the color setting variables, etc.) that Liberty BASIC has supported since globals were first introduced in LB2, are now promoted to true global variables.  Until now, these could only be set in the main part of the program, not in functions and subroutines.  That limitation has now been lifted.  See the code below for examples of this.
Example one:
    global true, false, font$
    true = 1
    false = 0
    font$ = "times_new_roman 10"
    call makeWindow
    print "WindowWidth was changed: "; WindowWidth
sub makeWindow
    if true <> false then
        notice "Hey, true isn't the same as false.  Whatta ya know?"
    end if
    WindowWidth = 350
    texteditor #main.te1,  8,  8,  250,  152
    textbox #main.tb1,  16,  192,  112,  24
    statictext #main.Statictext4, "Font_Name w h",  8,  168,  100,  18
    button #main.apply1, "Apply", [applyFont1], UL,  136,  192,  67,  24
    radiobutton #main.rb1, "Radiobutton 1", [set], [clear], 16, 226, 190, 20
    checkbox #main.cb1, "Checkbox 1", [set], [clear], 16, 256, 190, 20
    open "Untitled" for window as #main
    #main "font "; font$
    #main.te1 "The font is: "; font$
end sub
Example two:
'define a global string variable:
global title$
title$ = "Great Program!"
'Special system variables don't
'need to be declared as global,
'since they have that status automatically
BackgroundColor$ = "darkgray"
ForegroundColor$ = "darkblue"
'call my subroutine to open a window
  call openIt
sub openIt
  statictext #it.stext, "Look Mom!", 10, 10, 70, 24
  textbox #it.tbox, 90, 10, 200, 24
  open title$ for window as #it
  print #it.tbox, "No hands!"
end sub

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -