|
Tutorial 01: A Simple Program
Dec 15, 2008
© NSB Corporation. All rights reserved.
|
Purpose
The purpose of this tutorial is to demonstrate how a simple
program is created using NS Basic/Symbian OS. You should have NS Basic/Symbian OS 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/Symbian OS"
Program Development
1. Startup
- Start NS Basic/Symbian OS from the Start menu.
- At the initial screen select New Project
2. Modify Project Properties
- Change the
(Name) to "HelloPgm".
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 Design 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 Design 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 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 an installer called HelloPgm.sisx in folder c:\nsbasic\Download.
- The next step will be to download it to your device.
Congratulations !! You have now written your first NS Basic/Symbian OS
program.
Testing The Project
First, make sure your device is connected to your computer using the Nokia PC Suite or equivilent.
- Go into c:\nsbasic\downloads
- Double click on HelloPgb.sisx.
- Install as you would any other application.
- If you get "Certificate Error. Contact the Application Supplier", do the following:
- On the device, go to Tools
- App. Manager
- Highlight App. downllds.
- Click "Options"
- Select "Settings"
- Software installation: change from "Signed only" to "All"
- Run the app on the device
Extending the Tutorial
Let's explore some further features of NS Basic/Symbian OS. We'll
do this by modifying your first program to be more complicated.
Exit NS Basic/Symbian OS by choosing File and Exit from the menu.
Restart
- Restart NS
Basic/Symbian 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 it on your 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 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 Design 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's field object for display.
- Compile and
when error free, test on your device.