RealBasic_Intro

advertisement
REALbasic
Programming
Introduction


Application builder based on the BASIC
programming language
 BASIC = Beginners All-purpose Symbolic
Instructions Code
 Basic program created in 1960’s - teaching
people to program
REALbasic development environment is made up of
a rich set of graphical user interface objects (GUI)
 GUI - object orientated - uses icons, buttons,
boxes to assist with writing the program
Introduction




cont’
Computers only understand instructions in binary ( 1’s and
0’s) called machine language.
Programming in machine code would mean learning what
each binary code did. There are many.
To overcome this high-level programming languages were
invented. There are many C, C++, VisualBASIC, REALbasic,
FORTRAN, Pascal, Java ….
Some programming languages use an interpreter program to
convert the high-level code into machine code and then
execute it. This process is slow as, in simple terms, the
interpreter converts a line of code, executes it and then
moves on to the next line. (ie turns BASIC code into machine
code)
Introduction

Most languages have a compiler - programs that
translate the programming language into machine
code/language all at once which makes programs
execute faster. The converted program is then a
stand alon application (an exe file)


cont’
REALbasic has a compiler built into it - code executes as
fast as possible
Using a compiler you have two files, one containing
the code you have written and the compiled
“executable” file - the program.
REALbasic program Instructions

Launch REALbasic - it’s icon should be in the dock

Four separate windows
will open automatically
This is the Project Window it shows all the main elements
of your project.
It lists windows your application uses, menu bars
you make, objects used such as sounds, pictures,
databases and movies.

REALbasic program Instructions


By default, when opened the
Project Window shows your
application main window Window1, its menubar MenuBar1 and an item for
code associated with the
project - App.
You double click an item in the
Project Window to view or edit
it.
REALbasic program Instructions

This window is the Window
Editor.

This is where you build
windows, dialogue boxes,
alert boxes and so on for
your application. Each
window you create in a
program will have its own
Window Editor window and
it will be listed in the Project
Window.
REALbasic program Instructions

This is the Controls Palette.

You drag the interface objects
(referred to as controls), such
as buttons, labels, boxes to the
Window Editor to create your
applications interface.
REALbasic program Instructions

This is the Properties window.

It shows the list of names of
properties and their values for
the currently selected object in
your application
Events


An event is something that happens in a
window that can be detected by RealBASIC.
Examples of events are:




Clicking the mouse button while pointing at an
object
Pressing the tab key
Pressing a function key
Moving the mouse over an object
REALbasic - Lesson 1 - Project
1

You are going to create your first program:

Create a folder
RealBASICProjectsUsername

in your network folder
Open RealBasic and
save the “document” it
creates as
RealBASICProject1_username
Project 1

Drag a statictext
control into the top left
of the project window.

Notice that REALbasic
displays lines and
‘snaps’ the control to
the right spot - this helps
you to place and
align items
Project 1

Click on the Name: property
in the ID section and change
it to read st_Name

Click on the Text: property in
the appearance section and
change it to read Enter Name:
Save your work

Project 1

Drag an Editfield
control into the project
window to the right of the statictext control
Project 1


Change its Name: to ef_UserName
(one word, no spaces)
Save your work
Project 1

Drag a Pushbutton
control into the
bottom right corner of the window
Project 1 cont’




Change its Name: to pb_GreetMe
(one word, no spaces)
Change its Caption: to
Greet Me.
You will need to make the
button a little wider to get its
label to fit. Click on the button you should get its resize
handles - the same techniques
as you would use in any other
program
Save your work
Project 1 cont’




Double click on the PushButton
This opens the
window’s Code
Editor
This is where you
enter the actual
program code
for the window or
any of the objects
in it
It will open to the
most likely Event
for the control
Project 1 cont’


Controls in the window can contain
REALbasic code to tell them what to do when
particular
things happen
You will program
the button, so it
knows what to do
when it is clicked
Project 1 cont’

Type in the code exactly as you see it below:
Sub Action()
msgBox “Hello”
End Sub


You will notice that the first and last lines are
already entered for you
Save your work
Project 1 - cont’


REALbasic program code is not casesensitive
Save your work
Project 1 - cont’


Open the Debug menu
Choose Run
 REALbasic will display a working version of the
window you just created




If REALbasic gives you an error message of some kind, you
will have mistyped the code shown on the previous slide correct it and try again
When the program runs, type something into the
Editfield box, and click the Greet Me button
It will display exactly what you typed, in a dialog
box.
Click OK to close the dialog box, then choose Quit
from the file menu. This will return you to
REALbasic’s programming environment.
Lesson 2 - Project 1



We are going to make it do a better job of greeting someone.
Double click on the button, so the code editor window
displays the Action event handler for the button again.
Change the Action event to read:
Sub Action()
MsgBox “Hello, “ + UserName.text
End Sub


Save the project
Run it
**Note that there is a space after the comma
Project 1 - cont’







Let’s format the objects
You need to select the object
first so that the properties
window for that object appears
Alter the font, colour, and so on
for each object
Save the project
Run it …….
Quit the application
Project 1 - COMPLETED!
Download