QTP:How to insert double quotes in QTP string or message box?

 
I had a scenario where i had to display the message as – The operaration cannot be performed because “xyz” field is blank. To include double quotes in the QTP message or string
Now if i try to store the above message in a string as –

   1: string1 = "The operaration cannot be performed because "xyz" field is blank."

   2: msgbox string1 

We get the following error on running the above code in QTP.

String_error

There are two ways to handle this problem:-
1. Double the quotes (“”):
Use 2 double quotation marks to include a quote character in the string.

   1: String1 = "The operaration cannot be performed because ""xyz"" field is blank."

   2: msgbox string1 

The result is:

String_sucess1
2. Use ANSI character code – Chr(34):
Since, the ANSI code if quotation mark = 34, we can use Chr function.

   1: string1 = "The operaration cannot be performed because " & Chr(34) & "xyz" & Chr(34) & " field is blank."

   2: msgbox string1 

The result is:

String_sucess2

This Post Has 2 Comments

  1. vishnu

    Useful

  2. Unknown

    Thanks for sharing

Comments are closed.