NSB.MsgBox([callback, ]prompt[, buttons[, title]])
MsgBox opens a dialog box, and waits for the user to tap on a button. While it is displayed, no other actions may be taken by the user. However, this function does not halt the program: execution of the next statement will continue immediately. If you have multiple MsgBox statements in a row, only one will show.
The callback argument is the name of a subroutine or function in your program, which will be called when the control is dismissed. When the user clicks on button, callback will be called with one of the values in the MsgBox Return Values table.
prompt, is a string expression that is displayed in the body of the dialog box. It can be plain text or HTML.
The optional parameter, buttons, is a numeric or string expression that specifies which buttons to draw and which icon to use. The default value for buttons is 0. Other values are obtained by adding the desired constants from the Button Constant table. The values vbCritical, vbQuestion, vbExclamation and VBInformation can be added to the button value to specify a preset icon.
buttons can also be a comma separated string of button names. In this case, the name of the button is returned. An example of a custom button string would be “btn1,btn2,btn3”. To have a preset icon, append its number to the string, as in "btn1,btn2,btn3;32" for three custom buttons and a question icon. Names of buttons have to follow the rules for variables: no spaces or special characters are allowed.
A custom icon can be specified by adding “;” and the name of the icon within the button string. The icon should be 33x33 pixels, but will be resized if different. For example, "btn1,btn2;images/customicon.gif" would result in two custom buttons and a custom image for icon.
The optional parameter, title, is a string expression that is displayed in the title bar of the dialog box. If title is not supplied, the title of the app is used. If title is set to an empty string (""), the dialog header will be hidden for Android.
To dismiss an NSB.MsgBox from your program instead of waiting for the user, call NSB.closeMsgBox(). When displayed, the MsgBox has an ID of NSB_MsgBox.
NSB.MsgBox produces a nicely formatted message box, with a title and optional buttons. To do so, AppStudio creates a small modal form. Processing continues which it displays, which is a problem if you want to display another MsgBox in the next statement.
The easy (and ugly) solution is to use the alert() function instead:
alert("this is a message")
The more elegant solution is use MsgBox's function argument to call a function which displays the next MsgBox when the first one is dismissed.
Table 15: Button constants
|vbOKOnly||0||OK Button only|
|vbOKCancel||1||OK and Cancel buttons|
|vbAbortRetryIgnore||2||Abort, Retry, and Ignore buttons|
|vbYesNoCancel||3||Yes, No, and Cancel buttons|
|vbYesNo||4||Yes and No buttons|
|vbRetryCancel||5||Retry and Cancel buttons|
|vbCritical||16||Critical Message icon|
|vbQuestion||32||Warning Query icon|
|vbExclamation||48||Warning Message icon|
|vbInformation||64||Information Message icon|
Table 16: MsgBox return values
Title = "MsgBox Tour" 'Simple Message NSB.MsgBox("Hello World!") 'Simple Message with a custom title NSB.MsgBox("Brief Tour of MSGBOX!",0, Title) 'Yes/No Prompt. Call yesNoDone when finished NSB.MsgBox(yesNoDone,"Do you like this tour?", vbYesNo+vbQuestion, Title) 'Three Custom Buttons. Call custDone when finished. NSB.MsgBox(custDone,"How is NSB/App Studio?", "Fun,Great,Sweet", Title) 'Custom Button and Icon NSB.MsgBox("Who is the Happy Guy?", "Mario;mario.jpg", Title) Sub yesNoDone(result) If result=vbYes Then Text1.value="Yes" Else Text1.value="No" End Sub Sub custDone(result) Text2.value=result End Sub
(depends on button. See nsbMsgBox sample)