Projects, Forms, and Controls

From NSB App Studio
Revision as of 09:25, 31 August 2013 by Ghenne (talk | contribs)
Jump to navigation Jump to search

Section 2.5.1 Controls

A control is a visual object used by your program. Controls have Properties which can be queried and set, Methods which can be called as FUNCTION or SUB procedures, and Events which can be triggered by user actions, the operating system, or other programs.
A number of controls are included with App Studio. These include checkbox, commandButton, combobox, grid, textbox and other common objects.


Section 2.5.2 Control Events

An event is a call that a control makes to your program, as a result of an action in the control. For instance, if you have a commandbutton in your program, an event will take place when the user taps the button. If your button's name is "MyButton", App Studio will call the function MyButton_onclick() in your program. If you do not have such a function, the event is ignored.
Another example would be if you were performing an SQL operation. Incoming data will cause the Success_Function event to be sent, which will then call Function Success_Function in your program.

Section 2.5.3 Control Methods

A control can be hidden by using
myControl.hide
A control can be shown by executing
myControl.show


Section 2.5.4 Forms

A Form is a group of controls that are shown and hidden at the same time. Form names should be unique: not used also for a variable or another control. A good convention is to add frm in front as in frmHelp. Forms can be full screen or partial screen. More than one form can show at a time, so it’s possible to have two forms side by side on devices with large screens. Do this by setting the bounds of the form in the form’s properties.


Section 2.5.5 Form Methods

A form can be hidden by using
formName.hide
A form can be shown by executing
formName.show

To go to a new form,
ChangeForm(Form2)

To see the name of the current form
Msgbox NSBCurrentForm.id

To change the background color of a form, blank out 'backgroundimage' in Project Properties, then add these statements to your code:

Sub Main()
  document.body.style.backgroundColor=vbRed
End Sub

Section 2.5.6 Form Events

Show and Hide events are called when you use ChangeForm() to go to a new form.

Example

ChangeForm(Form2)

Function Form1_onhide()
  'save our work
End Function

Function Form2_onshow()
  'put in initial values
End Function

Section 2.5.7 Program Events

When a program is started, code is run in the following order:

  1. Global code in forms, in the order the forms appear in the Project Explorer. 'firstform' does not affect this.
  2. Global code in Project Properties and Global Code
  3. Form code in the first form's onshow() event. This is also the point where first form appears on the display. If you want to reconfigure some controls when the form first displays, this is the place to do it.
  4. Sub Main(), if present.

For clarity, it is best to always put all your global code in the Project Properties and Global Code section.
The forms are created at the same time as the global code is run.
After the first form is shown, a call is made to Sub Main(). If you have such a function, it will be executed.
When you exit the program, the window_onbeforeunload function is called. This is a good place to do housekeeping or save some data. If you return anything from this function, it is used in a confirm script.

Example

'Put this in your global code
MsgBox "This is the global code"
Sub Main()
  MsgBox "Main"
End Sub
Function window_onunload()
  MsgBox "Unloading!"
End Function

Section 2.5.8 Classes

BASIC

'Define a class like this
Function Person(name, gender)
   'Add object properties like this
   this.name = name
   this.gender = gender
End Function

'Add methods like this.  All Person objects will be able to invoke this
Function speakName()
  Print "Howdy, my name is " & this.name
End Function

Person.prototype.speak = Eval("speakName")

'Instantiate new objects with 'new'
bob = new Person("Bob", "M")

'Invoke methods like this
bob.speak() 'Prints "Howdy, my name is Bob"

JavaScript

// Define a class like this
function Person(name, gender){

   // Add object properties like this
   this.name = name;
   this.gender = gender;
}

// Add methods like this.  All Person objects will be able to invoke this
Person.prototype.speak = function(){
    alert("Howdy, my name is" + this.name);
}

// Instantiate new objects with 'new'
var person = new Person("Bob", "M");

// Invoke methods like this
person.speak(); // alerts "Howdy, my name is Bob"