Tutorial 01: A Simple Program

April 18, 2008

© NS BASIC 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/Desktop. You should have NS Basic/Desktop 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 clicks on the button, the program responds with the message  "Hello--Welcome to NS Basic/Desktop"

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) This command does nothing for Desktop programs but it's included to show how a program can be written for both CE and Desktop platforms.
Option Explicit
ShowOKButton True    ' Used for /CE, no-op for desktop

Sub CommandButton1_Click
   MsgBox "Hello -- Welcome to NS Basic/Desktop",0,"NS Basic"
End Sub

 

6. Save the Project

Testing The Project

Now we are ready to test the project. Select Start from the File menu.

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 screen. 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/Desktop program.

Extending the Tutorial

Let's explore some further features of NS Basic/Desktop. We'll do this by modifying your first program to be more complicated. Exit NS Basic/Desktop 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 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