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.
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"
Example 2:
Msgbox "Hello World", 16, "TestNBug" Msgbox "Hello World", 32, "TestNBug" Msgbox "Hello World", 48, "TestNBug" Msgbox "Hello World", 64, "TestNBug"
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 for Strings:
- Use double quotes (“”) to display strings in message box.
- Do Not use quotes to display the variable value message box.
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 .
How does the tool know about this ?
The following constants are used with the MsgBox function to identify which button user has selected.
- vbOK 1 OK button was clicked.
- vbCancel 2 Cancel button was clicked.
- vbAbort 3 Abort button was clicked.
- vbRetry 4 Retry button was clicked.
- vbIgnore 5 Ignore button was clicked.
- vbYes 6 Yes button was clicked.
- vbNo 7 No button was clicked.
The list of Numbers Game for Buttons :
Constant | Value | Description |
---|---|---|
vbOKOnly | 0 | Display OK button only. |
vbOKCancel | 1 | Display OK and Cancel buttons. |
vbAbortRetryIgnore | 2 | Display Abort, Retry, and Ignore buttons. |
vbYesNoCancel | 3 | Display Yes, No, and Cancel buttons. |
vbYesNo | 4 | Display Yes and No buttons. |
vbRetryCancel | 5 | Display Retry and Cancel buttons. |
vbCritical | 16 | Display Critical Message icon. |
vbQuestion | 32 | Display Warning Query icon. |
vbExclamation | 48 | Display Warning Message icon. |
vbInformation | 64 | Display 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.