Liberty BASIC Help Online

Text mode display
TEXT DISPLAY IN THE MAINWIN
Liberty BASIC is designed for building Windows programs.  It is also possible to write rudimentary text mode programs.
 
By default, each Liberty BASIC program has a main window, called the "mainwin."  This is a simple text display with scrollbars. 
 
Displaying Text
The standard PRINT command causes text to be displayed in the mainwin.
 
print "Hello World"
 
produces
 
        Hello World
 
After the expressions are displayed, the cursor (that blinking vertical bar | ) will move down to the next line, and the next time information is sent to the window, it will be placed on the next line down.  To prevent the cursor from moving immediately to the next line, add an additional semicolon to the end of the list of expressions.  This prevents the cursor from being moved down a line when the expressions are displayed.  The next time data is displayed, it will be added onto the end of the line of data displayed previously.
 
Usage:                  Produces:
 
  print "hello world"           hello world
 
  print "hello ";               hello world
  print "world"
 
  age = 23
  print "Ed is "; age; " years old"     Ed is 23 years old
 
Getting User Input
User input is obtained by use of the INPUT command in the mainwin.  Here is a simple example:
 
  'Ask the user a question
  input "Hi! What's your name?"; yourName$
  print "Nice to meet you "; yourName$
  end
 
The prompt may be expressed as a string variable, as well as a literal string:
 
  prompt$ = "Please enter the upper limit:"
  input prompt$; limit
 
Most versions of Microsoft BASIC implement INPUT to automatically place a question mark on the display in front of the cursor when the user is prompted for information:
 
  input "Please enter the upper limit"; limit
 
  produces:
 
    Please enter the upper limit ? |
 
 
Liberty BASIC makes the appearance of a question mark optional.
 
  input "Please enter the upper limit :"; limit
 
  produces:
 
    Please enter the upper limit: |
 
  and:  
 
input limit  
 
produces simply:
 
    ? |
 
In the simple form input limit, the question mark is inserted automatically, but if a prompt is specified, as in the above example, only the contents of the prompt are displayed, and nothing more.  If it is necessary to obtain input without a prompt and without a question mark, then the following will achieve the desired effect:
 
  input ""; limit
 
Additionally, in most Microsoft BASICs, if INPUT expects a numeric value and a non numeric or string value is entered, the user will be faced with a comment (something like 'Redo From Start'), and be expected to reenter.  Liberty BASIC does not automatically do this, but converts the entry to a zero value and sets the variable accordingly. 
 
 
Mainwin Size
It is possible to set the number of columns and rows in the mainwindow using the MAINWIN statement.  Here is how to set 40 columns and 20 rows:
 
  'Set a custom size!
  mainwin 40 20
  for x = 1 to 4 : for y = 0 to 9
    print y;
  next y : next x
  print
  print "1 This screen is forty columns"
  print "2 and twenty lines."
  for x = 3 to 19
    print x
  next x 
 
Clearing the Mainwin
The CLS statement clears previous text from the mainwin:
 
  'show a range of values
  for x = 0 to 4
    cls
    print "The sine of "; x + 0.1; " to "; x + 1
    for y = 0.1 to 1 step 0.1
      print "sine("; x + y; ") = "; sin(x + y)
    next y
    input "Press enter for more..."; go$
  next x
  end
 
Locating Text
 
Using LOCATE in the mainwin causes text to be printed at the x, y location specified.  These coordinates refer to the column and row of text, not to screen pixels.  This command functions in the same way as the QBasic LOCATE command and is used to position text on the mainwin.  Here is a short demo:
 
  'plot a wave
  for x = 1 to 50
    i = i + 0.15
    locate x, 12 + int(cos(i)*10)
    print "*";
  next x
 
Print TAB(n)
Liberty BASIC 4 has the ability to use the TAB function for formatting output.  "n" is the character location where the next output will be printed.  "tab(7)" causes the next output to print beginning at column (character) 7, while "tab(21)" causes the next output to print beginning at column 21.
 
    'show how tab() works
    print "x"; tab(7); "sine"; tab(21); "cosine"
    for x = 1 to 10
      print x; tab(7); sin(x); tab(21); cos(x)
    next x
    end
 
Printing columns with commas
A new feature of Liberty BASIC 4 is the use of commas for columnar printing in the main window.  Commas placed between outputs signal the starts of new columns.  Commas contained within quotation marks do not signal new columns.
    'a demonstration of printing columns using commas
    print "x", "sine", "cosine"
    for x = 1 to 10
      print x, sin(x), cos(x)
    next x
    end
 


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/