Free Web Site - Free Web Space and Site Hosting - Web Hosting - Internet Store and Ecommerce Solution Provider - High Speed Internet
Search the Web

Liberty BASIC Developer

 

Home
About
Current Issue
Past Issues
Links
FAQ
Contact

Liberty BASIC Developer

Vol. 1 No. 1 July 2001

Contents:

Editors Note

LB News

GOTO less programming

COMMAND Focus: Print

Site links

Feed back

Legal Stuff

Editors Note

Welcome to the first issue of Liberty BASIC Developer. This ezine is dedicated to the Liberty BASIC programming language written by Carl Gundel and the Liberty BASIC community at large. The purpose is to promote the use of this powerful but easy to use language for windows programs. Explore uses of the commands available in LB. Develop good programming techniques for all to benefit from.

Why start another LB publication? Well, there are a number of reasons. First, the personal gratification of producing something that is helpful to other programmers. Having control over what is produced or not produced in a publication. I suppose also to promote my own LB web site(can you believe that some one could be so blatant). In the process to learn to become a better programmer.

For this ezine to succeed I will need input from other LB user's, have a question you can't seem to answer, a piece of code that would be useful to others, or maybe like to have your own LB programs or web site high lighted. I think that just about anything goes as long as it related to Liberty BASIC.

In conclusion I hope that this ezine will be a benefit to all Lber's whether new or seasoned programmers. Let me know what you think.

Enjoy!

Neil Tremblay

top

LB News

The current version of Liberty BASIC is v2.02. It can be downloaded from the Liberty BASIC home page. See the site links section for the web address.

Version 3 of LB is under development. From viewing the captains log we can see that Carl is busy adding a couple of new commands and working out some bugs. Alpha testing should begin soon.

top

GOTO less programming

With all the recent message traffic on the lbexp news group about GOTO less programming I thought that this would be a good starter article for LBDev. When I first started reading the messages about this, my first reaction was you have got to be kidding. There is no possible way to accomplish this, or is there?

Having just written a lotto number generator program for myself, I thought that this would be a good chance to try and see if it could be really done. The code for the program flows as layed out below.

Initialize some variables
Make program window
Wait for some input
Events-
Combobox input, do some thing, GOTO Wait for some input
Radio button1 input, do some thing, GOTO Wait for some input
Radio button2 input, do some thing, GOTO Wait for some input
Radio button3 input, do some thing, GOTO Wait for some input
Cmd button input, do some thing, GOTO Wait for some input

So looking at this and what was being said in the news group I replaced the GOTO with the WAIT command. And what do you know, but my program still worked. So what is exactly happening?

To start with we have to remember that LB is an event based programming language. This is one of the things which makes it so powerful. So when a user performs some sort of an action eg. a button click, the program jumps to deal with this as long as it is not busy doing something else.

Ok, so why bother doing this, we are still waiting aren't we. Well yes you are still just waiting, what this does is it keeps your program control more defined. When you are drawing out your program flow, before you actually start programming, it will be more simplified.

Initialize some variables
Make program window
Wait for some input
Events-
Combobox input, do some thing, Wait for some input
Radio button1 input, do some thing, Wait for some input
Radio button2 input, do some thing, Wait for some input
Radio button3 input, do some thing, Wait for some input
Cmd button input, do some thing, Wait for some input

This now makes each event its little own code island. In addition because the end of each event handler ends in just a WAIT command you don't have to try and remember exactly what you named your main input loop eg. was that [main.loop] or was that [Main.Loop] I think you get the idea.

You can see the actual code for this program (Lotto) on the Left Coast Software site under the programs heading.

Happy programming!

top

COMMAND Focus: Print

Seeing as this is the first issue of Liberty BASIC Developer, I thought that it was appropriate to focus on the PRINT command. The reason being, it was the first command I used when learning Liberty BASIC. Come to think of it, it was probably the first command I used as I stood in the local Radio Shack trying out a TRS80 a few years back. Most likely it looked something like this:

print"Neil is great!" –ENTER-

And voila, but what should appear on the next line but,

Neil is great!

That first print command was all that was necessary to get me hooked on writing computer programs. And not to mention give my ego a boost that a computer had done what I told it to do. Even though Liberty BASIC does not support direct command execution like the older Interpreter BASIC’s, it is extremely more powerful. Lets take a look at the many ways in which it is used in Liberty BASIC.

The simplest form of this command is

print

At first look you may think that nothing will happen with just this one simple command. Don’t be fooled, what happens is even though no information was printed, a new line command is sent to the main window. You will be able to see this if you run the next few lines of code.

print
print"I am a computer programmer"
end

By looking at our main window we see a blank line above our simple sentence. In this next example we will break our sentence into 2 parts.

print"I am a computer "
print"programmer"
end

If you ran this code you would see the following in your main program window.

I am a computer
programmer

To get your sentence to print on a single line we will have to add a semicolon to the first line of code line this.

print"I am a computer ";
print"programmer"
end

Our code now outputs the following line in our main program window.

I am a computer programmer

In this example by adding the semicolon to the end of our first line of code we have inhibited the new line command being outputted by the print command. With the use of the semicolon we can build larger out strings with smaller amounts of data. I should note here that the print command is special in that it can accept alphanumeric data or strings as well as numbers. Take a look at the following example code and its output.

Print"I am 21 years old" ‘literal string
print"I am "; 21 ;" years old" ‘literal string and a numeric
begin\\$ = "I am " ‘string variable
ending\\$ = " years old" ‘string variable
age = 21 ‘numeric variable
print begin\\$;age;ending$ ‘string, numeric, string variable
end

I am 21 years old
I am 21 years old
I am 21 years old

By the way, if you believe the above line output maybe I could interest you in some fine property. All joking aside, we see that our output is the same for the 3 different print commands that we used. Their combinations available to output data to the main window are only limited by our imagination. The same rules above apply if you are wishing to send data to a serial disk file.

Within Liberty BASIC you have the ability to take advantage of the graphical nature of Windows. The print command is able to send data as well as commands to devices such as text boxes, buttons and graphics windows. Each of these devices has its own set of commands, which perform some action within them. Covering them all is beyond the scope of this article, but I will cover a few so that you will get an idea of their use. I will cover the following 2 as I have used them quit a bit.

Button

print #handle.ext, "string"
print #handle.ext, "!font facename pointSize"

Normally you set buttons displayed string when you declare it before opening a window. With this first print command you can change a buttons displayed string. The next command will change the font being used. Give this program a try to see what happens. Click the button a few times to see what takes place. You could also run from debug and see what happens as you step through the program.

Nomainwin
click = 0
BUTTON #main.b1, "start", [b1press], UL, 20, 20, 100, 50
open "Print example" for window as #main
print #main, "trapclose [exit]"
wait

[b1press]
click = click + 1
print #main.b1, "click";click
print #main.b1, "!font courier_new ";click
wait

[exit]
close #main
end

You can explore using the print command with other devices to see what the outcome is. Remember to refer to the help file included with Liberty BASIC. I hope that this article about using the print command will benefit you in some way or another as much as it has helped me.

top

Site links

http://lbdev.5u.com Liberty BASIC Developer home page

http://www.libertybasic.com Liberty BASIC home page

http://lcsoftlb.50megs.com Liberty BASIC software from the Left Coast. Editors home site

top

Feed back

All readers feed back is welcome whether its to do with this issue, future acticles or comments in general. Send your message to mailto:lbdev@lbdev.5u.com

Any one who wishes to submit an article for publication, please send it to the editor. mailto:editor@lbdev.5u.com

top

Legal Stuff

The Liberty BASIC Developer ezine and lbdev.5u.com are © Neil Tremblay 2001 all rights reserved.

top

 
Copyright (c) 2001 Neil Tremblay
2016