Difference between revisions of "NSB.MsgBox"

From NSB App Studio
Jump to navigation Jump to search
Line 1: Line 1:
[[File:NsbMsgBox1.png|frame|iOS 6 Style: simple box]]
[[File:NsbMsgBox1android.png|frame|iOS 7, Android simple]]
[[File:NsbMsgBox2.png|frame|iOS 6 Style: box with a button and custom image]]
[[File:NsbMsgBox2android.png|frame|box with a button and custom image]]
[[File:NsbMsgBox2android.png|frame|iOS 7, Android Style: box with a button and custom image]]
[[File:NsbMsgBox3android.png|frame|box with multiple buttons]]
[[File:NsbMsgBox3.png|frame|iOS 6 Style: box with multiple buttons]]
[[File:NsbMsgBox3android.png|frame|iOS 7, Android Style: box with multiple buttons]]

Revision as of 17:37, 16 February 2014

box with a button and custom image
box with multiple buttons

NSB.MsgBox(function, 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 the first one will show.

The function 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, function 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().

The appearance of NSB.MsgBox varies depending on whether it is running on an iOS or Android device. To override this, do

NSB.MsgBoxStyle=""  ' for iOS before iOS 7.
NSB.MsgBoxStyle="-android" 'for Android and iOS 7.

Table 15: Button constants

Constant Value Description
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

Constant Value Description
vbOK 1 Ok
vbCancel 2 Cancel
vbAbort 3 Abort
vbRetry 4 Retry
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No


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)
End Sub


(depends on button. See nsbMsgBox sample)

Related Items