Welcome to to the first in this series of tutorials for users of
Panoramic Basic. These tutorials were designed with beginners in
mind, but may contain ideas for older user as well.
Panoramic Basic (PB), is an easy to use programming language for
creating flexible and dynamic windows applications in the shortest
amount of time. The syntax is clear and easy to learn and understand
without sacrificing and performance when compared to other languages.
Here is a quick example:
- Code:
-
rem Set the windows width and height...
width 0, 400
height 0, 400
Now push the lightning bolt button on the toolbar to run the application
and you should see a window a popup with a width of 400 pixels and height
of 400. Only three lines and we have a window! (2 minus the comment)
Panoramic automatically defines the first window for you and stores it
in the system object 0. A system object can be thought of as a handle
from other languages. What the system object 0 does is, allow you
control or change aspects about the window through its number identifier,
in this case being 0.
Lets go over this code line by line...
- Code:
-
rem Set the windows width and height...
This line is known as a comment as will be ignored by the PB. The only
purpose of this line is to let the programmer write short lines that
explain what the code he/she has written does, or it allows the programmer
to make notes for future reference. In our case it states what the size
of the window will be, 400 wide and 400 high.
- Code:
-
width 0, 400
height 0, 400
Using the windows number identfier of 0, this line of code tell PB to
make the window 400 pixels wide, and 400 pixels high. There are ways
to set the exact postion of the window as well which we will cover
shortly.
Now lets add a button...
- Code:
-
rem Set the windows width and height...
width 0, 400
height 0, 400
rem Create a button to close the window...
button 1
caption 1, "Quit"
As you can see from the code above, the button gets a number identifier
as well, 1. Through this, we change anything about the button we
like, such as the title you see on the button. To change the button's
title we, use the caption keyword. If you run the program now,
you should see your window you created, plus a Quit button in the top
left corner, thats not very convienient so lets change it...
- Code:
-
rem Create a button to close the window...
button 1
caption 1, "Quit"
top 1, 170
left 1, 150
Remember when i said you could set the position of the window? Well you
can do the same with buttons, with any system object in fact, simply by
using the two keywords, top and left. Top, works along the
Y axis, up or down. Left works along the X axis, left to right. But using
these two keywords, you can place the button anywhere you like inside the
windows area, also known as the client area. But wait you say!! The button
does nothing when clicked! This is because we have to set an event for the
button before it knows what you need it to do. An event, simply tells the
button which action to perform, eg: close window, open next window, etc.
Before you can create an event handler for your button, you need to know
what labels are.
- Code:
-
rem The close window sub...
label QuitApp
The lines of code above, define a label in PB. A label can be thought
of as just that. If you had a list of chores to do, eg: Ironing, Cooking etc,
each chore you have to do has a name, and according to that name, each chore
has its own actions that you need to perform, such as cooking the roast or
letting the iron get hot. Its exactly the same in PB. You define a label that
covers what actions you need to perform. What this label also does is define
the name of the Sub which will perform these acions or commands. We will cover
Subs in a later tutorial but for now you can think of them as individual groups
of actions. Lets see this in action with the button we made, and the QuitAapp
label.
- Code:
-
label CloseApp
rem Create a button to close the window...
button 1
caption 1, "Quit"
top 1, 170
left 1, 150
rem Wait here...
end
rem The subs defined by the labels...
QuitApp:
terminate
Here we are introduced to a new keyword, <b>end</b>. The end keyword is placed
on the last line of our program, right before the labels we defined earlier begin
to take action. If we never placed the end keyword in our program, PB would run
straight down into our Subs, and our program would cease to run correctly. This is
not limited to PB only, but computer programming in general. To stop this behaviour,
you must place the end keyword, before any of your subs defined by the labels. After
the QuitApp label, there is a semi-colon, you can think of this as simply PB's way
of knowing where you are stating what actions need to be performed by that Sub. Again,
dont worry if you are unsure about Subs, they will be explained in depth.
In the next part of these tutorials, we will begin to learn how the event works and start to uncover the secrets of PB