NSB.MsgBox

From NSB App Studio
(Redirected from Nsb.msgbox)
Jump to navigation Jump to search
box with a button and custom image
box with multiple buttons


NSB.MsgBox([callback, ]prompt[, buttons[, title]])

Description

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. If you're working in JavaScript, prefix these names with NSB. i.e, NSB.vbCritical.

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.

Finally, buttons can be a string containing an html anchor with a data url. In this case, the data url is downloaded. See sample below.

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 as 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

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

Example

TITLE = "MsgBox Tour";

Button1.onclick = function() { //Simple Message
    NSB.MsgBox("Hello World!", NSB.vbOKOnly, " ");
};

Button2.onclick = function() { //Simple Message with a custom title
    NSB.MsgBox("Brief Tour of MSGBOX!", NSB. vbOKOnly, TITLE);
    //close the MsgBox if no answer in 5 seconds
    setTimeout("NSB.closeMsgBox()", 5000);
};

Button3.onclick = function() { //Yes/No Prompt
    NSB.MsgBox(Button3done, "Do you like this tour?", NSB.vbYesNo + NSB.vbQuestion, TITLE);
};

function Button3done(result) {
    if (result == NSB.vbYes) {
        Text1.value = "Yes";
    } else {
        Text1.value = "No";
    }
}

Button4.onclick = function() { //Custom Buttons
    NSB.MsgBox(Button4done, "How is NSB/AppStudio?", "Fun,Great,Sweet", TITLE);
};

function Button4done(result) {
    Text2.value = result;
}

Button5.onclick = function() { //Custom Button and Icon
    NSB.MsgBox("Who is the Happy Guy?", "Mario;mario.jpg", TITLE);
};

Button6.onclick = function() { //InputBox
    NSB.InputBox(Button6done, "What am I thinking?", "InputBox Example");
};

function Button6done(result, value) {
    if (result == NSB.vbOK) {
        Text3.value = value;
    } else {
        Text3.value = "Cancel";
    }
}

function downloadFile(data) {
  button = `<a download="data.txt" href="data:,{$data}">Download File</a>`;
  NSB.MsgBox("Your file is ready to download", button);
}

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

Sub downloadFile(data)
  button = `<a download="data.txt" href="data:,{$data}">Download File</a>`
  NSB.MsgBox("Your file is ready to download", button)
End Sub

Output

(depends on button. See nsbMsgBox sample)

Related Items

MsgBox