|
Tutorial 01: A Simple Program
February 12, 2007
© NSB Corporation. All rights reserved.
|
Purpose
The purpose of this tutorial is to demonstrate how a simple
program is created using NS Basic/Palm. You should have NS Basic/Palm installed
before beginning this tutorial.
Description of the Program
The program to be developed will display a form with a button
on it. When the user taps the button, the program responds with the message
"Hello--Welcome to NS Basic/Palm"
Program Development
1. Startup
- Start NS Basic/Palm from the Start menu.
- At the initial screen select New Project
2. Modify Project Properties
- Change the
(Name) to "HelloPgm".
- Change the
Creator ID to "Hllo"
3. Modify Form Properties
- You should
now see a blank screen with the title "Form1"
- Select the
form in the Project Explorer by clicking on it.
- In Properties,
change (Name) to "Hello"
4. Add a button to the form
- Select button
("OK") in the Toolbox by left clicking on it
- Move the
cursor to the desired location within the Palm Screen
- Click the
left mouse button to place the button object on the screen
Change the button's text:
- Click on
the new button in the Palm Screen
- In the Properties
window, change Label to Tap Here
Resize the button:
- Select the
button by left clicking on it
- Position
the mouse cursor to any resize marker around the button
- Depress the
left mouse button and drag the object to a different size
- Release the
left mouse button to stop the action
Relocate the button on the screen:
- Select the
button by left clicking on it
- Position
the mouse cursor to the middle of the button
- Depress the
left mouse button and drag the object to some other screen location
- Release the
left mouse button to stop the action
5. Add commands to be executed when the button is tapped
6. Save the Project
- Select "File"
from the top main menu
- Select "Save
project" and save your program as HelloPgm
- This will
save your project in the directory c:\NSBasic\Projects under the name HelloPgm.prj
- All form
definitions, form objects, all code, and other project info are saved into
the one project file.
7. Generate the Downloadable Palm app
- Select "Run"
from the main menu.
- Select "Compile
HelloPgm" from the dropdown menu.
If you have any errors, an error message will appear and
the code window will appear with the section of code where the error occurred
highlighted. Errors must be corrected and Compile repeated until there are no
more errors. If you do not have errors, a message box will appear showing the
size of the compiled application.
- If you corrected
any errors, you should re-save the project.
- This action
creates a downloadable file in the c:\NSBasic\Download directory: c:\NSBasic\Download\HelloPgm.prc
- The file
must be downloaded to the Palm device or to POSE to execute your project.
Congratulations !! You have now written your first NS Basic/Palm
program.
Testing The Project
Test Using the POSE
Make sure you have POSE installed and working before trying
this. Instructions for installing POSE are in the ReadMe file.
- In the Tools
menu, select Options, then the Compile/Download tab. Select Send to Palm OS
Emulator and Run Immediately in the After Compile section.
- Start POSE
from the Run menu
- Load the
PRC file by clicking the right mouse button and select Load
Test Using Your Palm Device
- In the Tools
menu, select Options, then the Compile/Download tab. Select Hotsync to Device
in the After Compile section
- From the
Run menu, select Download (project name).
- Hotsync as
you normally would do with your device.
- After the
Hotsync completes, tap the application menu button.
- Select the
HelloPgm icon and your program should begin execution.
Extending the Tutorial
Let's explore some further features of NS Basic/Palm. We'll
do this by modifying your first program to be more complicated.
Exit NS Basic/Palm by choosing File and Exit from the menu.
Restart
- Restart NS
Basic/Palm from the Start menu.
- The first
screen will list recent projects you have worked on, so that you may easily
pick one for modification.
- Select the
HelloPgm project by clicking on it.
- The project
will load into the IDE and show you the project as you last left it.
Revision: Change the message
- Double click
on the button to bring up the code window.
- Enter the
following code after the SUB statement
Dim s as string
Dim d as date
d=today()
s=str(d)
- Change the
MsgBox statement to be
MsgBox "Today is " + s
Revision: Add code at program startup
- From the
menu, select Project...Startup Code
- After the
Sub line, enter this command:
msgbox "HelloPgm will continue when you tap on OK"
This code will be executed when the program starts execution.
The program displays the message and waits until the user taps on the OK button
- Compile the
program. If error free, test using POSE or your Palm device.
Revision: Code at Form display time
This change will add a field which shows the time-of-day.
Another button will be added to cause the time to be updated with the latest
time.
Add a field to the form to be used to display the time of
day
- Select the
field object from the Toolbox by clicking on it. The field object looks like
"T".
- Move the
cursor to the desired screen location and left click to place the field object.
- Select the
object by left clicking on it.
- In the Properties
Window, change the field's Name to "fldTime"
- Resize the
object as needed.
Add code to fill in the time-of-day when the form displays
- Right click
on the form name in the Project Explorer
- Select "View
After Code"
- Enter the
following code after the SUB line
dim wk as string
dim t as time
t = now()
wk = str(t)
fldTime.text = wk
This code will set the time of day into the field object
"fldTime" just after the Palm device displays the form to the user.
The statement
t = now()
gets the current time and stores it in the time variable
"t". The str function converts the internal time format into a text
string of the format hh:mm:ss which is the used to store into the field object
for display.
The above code could be compressed into one statement as
fldTime.text=str(now())
Add a button to redraw the form so that the latest time appears
- Select the
button object in the toolbox
- Place it
on the Palm Screen with a left click
- Select the
object
- In the Properties
Winddow, enter "Redraw the screen" as the button's Label.
- Resize object
as needed.
Add code to the button to cause the redraw
- Double click
on the button
- Enter the
following statement after the SUB line
Redraw
- Close the
code window
- This will
cause the entire screen to be redrawn. This will trigger the code supplied
for the form that is executed before the form objects are redrawn. This code
fills in the latest time to the formÅfs field object for display.
- Compile and
when error free, test using POSE or download to your Palm device.