Tutorial 02: Multiple Forms

May 01, 2008

© NSB Corporation. All rights reserved.

Purpose

The purpose of this tutorial is to help learn a few more NS Basic/Symbian OS programming techniques. You should complete Tutorial #1 before beginning this tutorial. In this tutorial, the techniques of using multiple forms will be covered.

Description of the Program

The program to be developed has two forms. Form #1 allows the user to enter a birthdate and name. Form #2 shows the values of the previously entered birthdate and name plus it tells on what day of the week the birthdate occurred.

Program Development

1. Startup

2. Modify Project Properties

3. Modify the First Form's Parameters

4. Build Form 1 Objects: Add a date selector for the birthdate

Add a field to enter the user's name:

Add a button to transfer to form #2

5. Create the Second Form

6. Create objects for Form 2

Add a text prompt before the birthday:

Add a field where the birthday will be shown:

Add a text prompt before the name :

Add a field where the name will be shown:

Add a text prompt before the day-of-the-week:

Add a field where the day-of-the-week will be shown:

Add a button to allow transfer back to form # 1:

7. Enter Code for Program Startup

	Global MyName as String
	Global MyDate as date
	MyDate=ToDate("1999/01/01") 

The purpose of this code is to supply global variables for MyName and MyDate so these values can be used throughout the program in multiple code sections

Give MyDate a valid date value because it is used in a date popup  command which requires that the date be valid. The user will actually select their own birthday in the date popup routine and overwrite this date.

No further action is required. NS Basic/Symbian OS automatically displays the program's first form at the start of program execution.

The Project Explorer now shows "(Startup)" next to the project name to indicate that there has been program code supplied there.

8. Provide Code for Form 1 Objects

Set Form 1 as the current form displayed by right clicking on it in the Project Explorer and selecting "View Object"

Code to cause the popup date entry form to appear:

When the user taps the birthday selector on Form 1, we want the standard date selector popup to appear. We must supply code to the selector object on Form 1 to cause this to happen.

	Dim result as integer
	result=PopupDate(MyDate,"What is your birthday?")
	selDate.text=str(MyDate) 

This code does the following:

9. Code to transfer to Form 2

When the user taps on the "Show the Day of the Week" button, we want Form 2 to appear.

	MyName= fldName.text
	NextForm "My Form 2" 

This code does the following:

10. Provide Code for Form 2 Objects

Supply code to be executed after the form is drawn

	fldName2.text=MyName
	fldDate2.text=dateMMDDYY(MyDate)
	fldDayNumber.text=str(DayOfWeek(MyDate)) 

This code fills in form fields with values before the form displays.

11. Supply code for the Go Back button to go back to Form 1

	NextForm "My Form 1" 

When this button is selected, the program will just cause Form 1 to re-appear and the user can try another date.]

This will save your project as c:\NSBasic\MyProject.prj. All form definitions, form objects, all code, and other project info are saved into the one project file.

12. Generate the Installer

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\myProject.sisx 

The file must be downloaded to the device to execute your project.

Congratulations !! You have now written your second 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.