Liberty BASIC Help Online

String Literals and Variables
Literal Strings
A string literal always starts with a quotation mark and always ends with a quotation mark.  No quotation marks are allowed in between the starting and ending quotation marks.  Here is an example that prints a string literal in the mainwin.
    print "Hello World"
The program above would produce this in the mainwin:
    Hello World
String Variables
There are special variables for holding words and other non-numeric character combinations.  These variables are called string variables (they hold strings of characters*).
    *Characters are:
      Letters of the alphabet ; abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
      Digits 0123456789 ;
      Any other special symbols like: , . < > / ? ; : ' " [ ] { } ` ~ ! @ # $ % ^ & * ( ) + - \ |    etc . . .
String variable names must end with a $ (dollar sign).  Text is assigned to a string variable using the equals sign ( = ).  This example assigns "Hello World" to the string variable hello$ and then prints it in the mainwin.
    hello$ = "Hello World"
    print hello$
The program above produces this in the mainwin:
    Hello World
NOTE  -  A string can have zero characters.  Such a string is often called an empty string.  In BASIC, an empty string can be expressed in a string literal as two quotation marks without any characters between them.  For example (noCharactersHere$ is the name of our string variable):
    let noCharactersHere$ = ""
Two strings of text can be joined together (concatenated), either as variables, literals or both.  This is accomplished by use of the plus sign ( + ).
    varOne$ = "Hello"
    varTwo$ = "World"
    varThree$ = varOne$ + " " + varTwo$
    print varThree$
The program above produces this in the mainwin:
    Hello World
It is also possible to use the semi-colon ( ; ) to add, or concatenate strings.
    varOne$ = "Hello"
    varTwo$ = "World"
    varThree$ = varOne$ ; " " ; varTwo$
    print varThree$
Some characters do not display on the screen, but instead they format the text output.  A combination of carriage return and line feed causes text printed after it to display on the next line down.  These non-keyboard characters can be accessed with the CHR$(n) function.  "n" is be the ascii value of the desired character.  In the case of a CRLF as described here, the character for "carriage return" is chr$(13).  The character for "line feed" is chr$(10).  The following code inserts a carriage return, forcing the text to print on two lines.
    print "Hello" + chr$(13) + chr$(10) + "World"
The double quotation mark is represented by CHR$(34).  To cause a double quotation mark to print, the character 34 is included, like this:
    print chr$(34) + "Hello World" + chr$(34)
    "Hello World"
In general, variables used in the main program code are not visible inside functions and subroutines.  Variables inside functions and subroutines are not visible in the main program.  Liberty BASIC 4 introduces the GLOBAL statement to create global variables. Variables declared as GLOBAL can be seen everywhere in a program.  See GLOBAL. The special system variables like WindowWidth, WindowHeight, etc. now have true global status.  GLOBALS are specified and used like this:
global filename$, author$, title$
filename$ = "readme.txt"
author$ = "John Q. Programmer"
title$ = "Great Idea"

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -