Tutorial 01: A Simple Program

February 01, 2010

© NSB Corporation. All rights reserved.

Contributed by Tom Newman, Mission Peak Designs


Purpose

The purpose of this tutorial is to demonstrate how a simple program is created using NS Basic/CE. You should have NS Basic/CE 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/CE"

Program Development

1. Startup

2. Modify Form Properties

3. Add a button to the form

Change the button's text: Resize the button: Relocate the button on the screen:

 

5. Add commands to be executed when the button is tapped

The last two lines are not required but recommended in all your programs. Option Explicit ensures that all variables are defined first (using the DIM statement). ShowOKButton places an OK button on the output screen of CE devices so the program can be closed (the default X button only minimizes the program).
Option Explicit
ShowOKButton True    ' Used for /CE, no-op for desktop
Sub CommandButton1_Click
   MsgBox "Hello -- Welcome to NS Basic/CE",0,"NS Basic"
End Sub

 

6. Save the Project

Testing The Project

Now we are ready to test the project. You can either download and run the program on a CE device or on the Microsoft Microsoft Device Emulator. Please refer to the instructions in Tech Note 23: Using the Microsoft Device Emulator, for information about installing and running the Microsoft Device Emulator. If you plan to run on an actual device, skip this step.

Starting the Microsoft Device Emulator

If you plan to test the program on the Microsoft Device Emulator it needs to be installed and running before it can be used.

Running the Program

Note: By default, the project is saved every time the program is run. As a shortcut you can press F5 to save and start the program.

Any errors will appear in a message box on the CE device/emulator. The message box displays the error and line number where the error occurred. Errors must be corrected and Start repeated until there are no more errors.

Congratulations !! You have now written your first NS Basic/CE program.

Extending the Tutorial

Let's explore some further features of NS Basic/CE. We'll do this by modifying your first program to be more complicated. Exit NS Basic/CE by choosing File and Exit from the menu.

Restart

Revision: Change the Message

	Dim s
	s = date 
  	MsgBox "Today is " & s,0,"NS Basic" 

 

Revision: Add Code at Program Startup

This change will add a message box that's displayed when the program first starts.
  	msgbox "HelloPgm will continue when you tap on OK",0,"NS Basic"

Revision: Add Code at Form Display Time

This change will add a label which shows the time-of-day. Another button will be added to update the label with the latest time.

Add a field where the Time of Day will be shown:

Add a button to refresh the Time of Day field:

Note: You can press F5 (Start) after you added or changed a visual design and before you add the code to support the visual changes. The program will download and execute and the new objects will be displayed (but not useable). This can be useful for prototyping a new design or getting the visual design right before adding the code.

Add code to fill in the time-of-day when the form displays

	lblTimeField.Caption = Time
	lblTimeField.Caption = Time

Your code should look like the following:

Option Explicit
ShowOKButton True    ' Used for /CE, no-op for desktop

MsgBox "HelloPgm will continue when you tap on OK",0,"NS Basic"

Sub CommandButton1_Click
   Dim s
   s = Date
   MsgBox "Today is " & s,0,"NS Basic"
End Sub

Sub Hello_Load
   lblTimeField.Caption = Time
End Sub

Sub cmdRefreshTime_Click
   lblTimeField.Caption = Time
End Sub