|
NS Basic/Desktop Tutorial #2:
A program with multiple Forms
© NS BASIC Corporation. All rights reserved.
|
Purpose
The purpose of this tutorial is to help learn a few more
NS Basic/Desktop 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
- Start NS Basic/Desktop Desktop IDE from the Start menu.
- At the initial
screen select Standard Project
2. Modify the First Form's Parameters
- You should
now see a blank form with the title "Form1"
- Select the
form in the Project Explorer by clicking on it.
- In the Properties
Window, change the Name to "MyForm1"
3. Create objects for Form 1
- Click on the Date object in the Toolbox.
- Move the
cursor to the form where you want the object to appear and click the left
mouse button.
- Click on
the object to select it.
- Set the Name to "dateBirth3"
Add a TextBox to enter the user's name:
- Click on
the TextBox object in the Toolbox (looks like "ab")
- Click the
left mouse button to place the TextBox object on the form
- Click on the object to select it.
- In the Properties Window, change the Name to "textName1"
- In the Properties Window. enter "Enter Your Name" as the Text.
Add a CommandButton to transfer to Form 2
- Select the CommandButton object in the Toolbox.
- Place it
on the form and click on it to select it.
- In the Properties
Window. enter "Show the Day of the Week" as the Caption.
4. Create the Second Form
- Select "Project"
from the top main menu
- Select "Add
Form" from the menu
- In the Properties
Window, set the Name to "MyForm2"
5. Create objects for Form 2
Add a Label before the birthday textbox:
- Select the
Label ("A") object from the Toolbox
- Place on
the form and click on it to select..
- In the Properties
Window, enter "Birthday =" as the caption.
Add a TextBox where the birthday will be shown:
- Select the TextBox object from the Toolbox
- Place on
the form and select it
- In the Properties
Window, change the Name to "textDate2"
Add a Label before the name :
- Select the
label object from the Toolbox
- Place on
the form and select it
- In the Properties
Window, enter "Name =" as the caption
Add a TextBox where the name will be shown:
- Select the TextBox object from the Toolbox
- Place on
the form and select it
- In the Properties
Window, change the name to "textName2"
Add a Label before the day-of-the-week:
- Select the
label object from the Toolbox
- Place on
the form and select it
- In the Properties
Windows, enter "Day-of-week =" as the Label
Add a TextBox where the day-of-week will be shown:
- Select the TextBox object from the Toolbox
- Place on
the form and select it
- In the Properties
Window, change the name to "textDayName"
Add a button to allow transfer back to form # 1:
- Select the CommandButton object from the Toolbox
- Place it
on the form and select it
- In the Properties
Window, enter "Go Back" as the Caption
6. 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.
- Go back to Form 1 by double clicking on MyForm1 in the Project Explorer.
- Double click on the "Show Day of Week" button to bring up its Code Window.
- Enter these lines of code after the SUB line:
MyForm1_Hide
MyForm2_Show
This code hides the objects on Form 1 and displays the objects on Form 2.
7. Provide Code for Form 2 Objects
- Double click on MyForm2 in the Project Explorer to go to Form 2.
Supply code to be executed after the form is drawn
- Double click any part of the form which doesn't have an object underneath
to open the code window.
- Enter these
lines of code after the SUB MyForm2_2_Load line
textName2.text = textName1.text
textDate2.text = dateBirth3.text
textDayName.text = WeekDayName(WeekDay(textDate2.text))
This code fills in form's TextBoxes with values before the
device displays the form to the user.
- It sets the
TextBox on the form that contains the user's name to the value from the textbox on Form 1.
- It sets the
TextBox on the form which contains the birthday to the value from date picker on Form 1. This is the value entered on Form 1 by the user using the
date popup routine.
- It sets the
TextBox on the form that contains the Day-of-week. It does this by using the function
WeekDay to create a number from 1 to 7, passing the value to the function
WeekDayName to get the string representation of the day of week, and supplying it as input
the birthday in MyDate.
8. Supply code for the Go Back button to go back to Form 1
- Double click
on the button to bring up the Code Window
- Enter this
code after the SUB line
MyForm2_Hide
MyForm1_Show
When this button is selected, the program will just cause
Form 1 to re-appear and the user can try another date.
Save the project as Tutorial2 in a directory you like.
All form definitions, form objects, all code, and other project info are saved
into the one project file.
12. Generate and test the executable file
- Select Start from the Run 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 run repeated until there are no
more errors.
Congratulations !! You have now written your second NS Basic/Desktop program.