Message box in UFT QTP ? MsgBox()

msgbox in UFT QTP

 

Message box is a good feature for displaying user defined messages during run time. In this post, we will look at different types of message boxes available in UFT QTP.

MsgBox is used to display message on a Dialog Box during run time, waits for the user to click a button, and returns a value that indicates which button the user clicked.

 

Syntax :

The syntax is quite simple

MsgBox(prompt[, buttons][, title][, helpfile, context])

Just type ‘Msgbox’ and enter Message which is to be displayed, Buttons, Title and Helpfile. All of these are not mandatory, you can use with any combination.

 

Message box syntax in UFT QTP

Buttons–  These are available as predefined in UFT, for eg. if select 1 then displays 3 button with ‘Yes’ , ‘NO’, and ‘Cancel’. below are the examples related to buttons and syntax.

 

Example 1:

Msgbox, Message to be displayed, Button, Title of the Message box

Msgbox "Hello World", 0, "TestNBug"
Msgbox "Hello World", 1, "TestNBug"
Msgbox "Hello World", 3, "TestNBug"

 

Message-box-Example in UFT QTP

 

Example 2:

Msgbox "Hello World", 16, "TestNBug"
Msgbox "Hello World", 32, "TestNBug"
Msgbox "Hello World", 48, "TestNBug"
Msgbox "Hello World", 64, "TestNBug"

 

Message-box- Example in UFT QTP

 

How to Display multiple lines in single Dialog box

In the example below ‘&’ is used to concatenate and ‘VBNewLine’ is for splitting into next line, the rest of the syntax is same.

Msgbox "Hello" & VBNewLine & "Welcome" & VBNewLine & "Have a "

 

Message-box-Example for multiple lines

 

Message Box for Strings:

  • Use double quotes (“”) to display strings in message box.
  • Do Not use quotes to display the variable value message box.

 

Message-box-strings in UFT QTP

 

Message box Return value :

In the definition it is described as ‘MsgBox Function returns a value indicating which button the user clicked‘. In the below image, ‘1’ is taken for button, which means ‘OK’ button is clicked .

Message-box-Return value in UFT QTP

 

How does the tool know about this ?

The following constants are used with the MsgBox function to identify which button user has selected.

  1. vbOK                         1              OK button was clicked.
  2. vbCancel                   2              Cancel button was clicked.
  3. vbAbort                     3              Abort button was clicked.
  4. vbRetry                     4              Retry button was clicked.
  5. vbIgnore                   5              Ignore button was clicked.
  6. vbYes                         6              Yes button was clicked.
  7. vbNo                          7              No button was clicked.

 

The list of Numbers Game for Buttons :

 

ConstantValueDescription
vbOKOnly     0Display OK button only.
vbOKCancel     1Display OK and Cancel buttons.
vbAbortRetryIgnore     2Display Abort, Retry, and Ignore buttons.
vbYesNoCancel     3Display Yes, No, and Cancel buttons.
vbYesNo     4Display Yes and No buttons.
vbRetryCancel     5Display Retry and Cancel buttons.
vbCritical    16Display Critical Message icon.
vbQuestion    32Display Warning Query icon.
vbExclamation    48Display Warning Message icon.
vbInformation    64Display Information Message icon.

 There are other values like 256, 512 ,768, 4096 which are not listed in the table above as their usage is limited. With this we come to the end of Msgbox post in UFT . In case of any issues , please post in the comments below.