Liberty BASIC Tutorial

The BASICS Liberty BASIC is an easy to learn Programming Language Developed by Shoptalk Systems It has many features borrowed from liberty basic, shoptalk system's popular commercial product It is very similar to another language known as QBASIC It has a very good advantage over most other basics, like QBASIC, Quich BASIC and GW basic, this is the advantage of being able to write windows programs as well as text mode programs. All you need to get started is to download the Liberty basic editor

Top Of Page

A simple Text Program We will now learn the basic syntax for writing text mode programs

First run the just basic editor that is located in the start menu in the just basic folder Now start a blank page and we are ready to begin The first command which will be used over and over even in you later programs is very important but simple This command is named 'Print' and in text mode programs it it simple to use. The print command sends text to the screen Example:

print "Hello World" Will produce:

Hello World very easy wasn't it

All text that is to be sent to the screen or contained in a variable must be enclosed in quotation marks

Top Of Page

this prints the contents of the variable number which is what we typed before and the semicolon is used to seperate the literal from the variablle you wolud not need a semicolon if you just wanted to print the contents of the variable without any other text Example: print number Also you do not have to tye variables. print is used to send text to the screen "you typed" . you have to use a semicolen to seperate a literal from a variable Line 2 . number print "You typed number". number print . you can declare them in you code Example number = 7 Top Of Page . number This might seem difficlult but i will make it easier by steping through it step by step Line 1 .this is a literal.number .Getting Input from the user and using variables Every computer program ive ever seen usually at some point nedds to ask the user to type in something This can be done using a new statement known as input it is similar to the print statement but has something added to the end.This is the part that tells basic that it is going to get input "Please type a number" . this gets written on the screen before the user types . A program Using input input "Please type a number".this tells basic that the what the user types in gets put in a variable called number.This prints "you typed" . number input .input "please Type a number".as we know. number .Print "You typed ".

05 total = tax + amount print "The tax is ". total This will calculate a 5% sales tax on the amount entered Top Of Page Comments To better help you understand your own programs. tax . amount tax = amount * 0." and the total is".Mathmatics With the numeric variables we have used so far we have not done anything to them in this section i will show you how to use mathmatical operations + of course means plus . you can add commentary to them that tells whoever is reading it how it works There are two ways to do this The first is rem Example: .means minus * means multiplication / means division Example print 5 + 5 will produce 10 You can also do maths with variables Here is an example program that shows all of the things we have learned so far input "Please type a dollar and cent amount".

total Or you can use a method which many prefere which is to add a ' the advantage of this is that you can put this on the end of a line of code. Eg. tax . print "Hello" ' writes hello you cannot do this with rem when just basic encounters a comment it skips it so you can wite anything you want and the compiler wont care You might not need comments yet but they will be really helpfull when you write bigger programs Top Of Page String Variables Liberty basic not only lets you ask the user for a number but also has ways of using words as well. amount tax = amount * 0.rem this is a tax program input "Please type a dollar and cent amount".05 rem calculate the tax total = tax + amount rem display the total print "The tax is "." and the total is". This is done in the same way you ask for a number. word$ print "you wrote ". if name1$ was "Brian" and name2$ was "Smith". name$ = name1$ + name2$ In this example. word$ You can also use a plus symbl + to add strings together. the contents of name$ would be "BrianSmith" . all you have to do is add a dollar sign $ on the end of the variable name and it becomes a string Example: input "type a word".

the gosub command skipps to line and when it sees return it jumps back to where it was called. Branch labels must be written like this [baranchname] A program can have as many or little brach labels as you want. Example: [start] print "hello 1" gosub [part] print "hello 2" [part] print "hello 3" . last$ full$ = first$ + " " + last$ print "Your full name is "+ full$ Top of Page Branch Labels. like this you should add a space in between. Ther is also a command called gosub.You should remember if adding names etc. Goto and Gosub When Writting our programs we will often need to jump to certain points and return. first$ Input "Type you second name". This can be done with branch labels and a command called goto. When you want to jump to a cretain point type goto [branch] this will skip to the point of the program called branch Example of a branch label using program: [start]print "hello" goto [label] print "hello 2" [label] print "hello 3" In this example the program will not print hello 2 because it automaticly jumps to [label] and skipps the print "Hello 2" line. Example: Input "Type your first name".

Only put return in branch labels that are gosubed to not goto. it goes to part and when it sees return it goes back to after the gosub command. text$ length = len(text$) print length in this example. Liberty BASIC Includes many predefined functions that you can use.return By doing this the program will print in this order hello 1 hello 3 hello 2 It does this because when it sees the line gosub [part]. Note: Be carefull with gosub. Top of Page Functions in liberty BASIC In liberty basic you can manipulate numbers and strings in ways that can be used to change the content. Different functions are used to return different values. finally the relult is printed on screen Left$(string$) This function returns the first characters in the string specified by the number. Usage: . like variables functions with the dollar sign ($) on the end return a string And functions without a dollar sign return a numeric value Functions will normally have their name then in brackets the variables and information it needs to make its calculation Here is a short list of functions to get you started. if you use goto and the program encounters a return statement. there will be an error. the user types something in which is then stored in a variable called text$ then the length of text$ specified by len(text$) is stored in the varible length. LEN (string$) Len is short for length and is used to see how long the string is in characters Usage: Input “type some text”.

number2) VAL(string$) The val function returns (if the string in question contains a number or numbes) the numbers in the string Eg. number) Mid$(string$) This returns the of characters in the string in the middle Usage: Input “Please enter a string :”. number$ Print “the numeric version is “. Usage: Input “type some numbers and they will be put in a string”. text$ Input “how many characters to the right? ” number Print right$(text$. it returns the characters to the right of the string Usage: Input “Please enter a string :”. number Print “the integer version is”. text$ Input “how many characters to the left? ” number Print left$(text$. number2 Print mid$(text$. int(number) There are many more functions. val would return a numeric version that can be used in mathematical calculations. number. number) You do not have to use a variable to specify how many characters also You can just type the number if wanted Print left$(text$. text$ Input “how many characters to the left? ”. see the liberty basic help file . for a complete list. (An integer is a number without a decimal point and following numbers) Eg int(5. val(number$) There are also functions for dealing with numbers Int(number) This function returns the integer value of a number.Input “Please enter a string :”. number Input “how many characters to the right? “. 3) Right$(string$) This function is the opposite of left$.5) would return 5 Usage: Input “Type a number with decimals”. If the user types “234” into a variable that is a string.

you have to write the font name into as special variable. This is PrinterFont$. You do not have to just include one atribute. Please note that it must be in capital or it will not work.Top of Page Printing Text OK. you can include any or all three if you want. For this you must use the LPRINT command. The attributes ar : Bold. Now i'll show you how to send text to the printer. PrinterFont$ = "Arial 10 bold italic underlined" . Italic and Underlined. PrinterFont$ = "Arial_Black 20 bold" See that the fiont name has to have _ insted of a space. This can be done as simple as sending text to the screen. Just use it like this: lprint "hello i'm being printed" If you would like to change the font that the text is printed in. Change it like you would any other variable.

Sign up to vote on this title
UsefulNot useful