Forum Discussion

twhitehouse's avatar
twhitehouse
Contributor
9 years ago
Solved

Double quotes added to variables

At times, double quotes seem to be added to string variables in Test Complete.  This may be a vbscript issue, I am not sure.  However, I have seen that a variable could end up having its value change like this:

 

"data"

""data""

"""data"""

 

The more I keep using it, the more double quotes get added to the value of the variable.  To bypass, I actually started creating copies of the variable since the value was not going to change anyways like so:

 

Dim data1

Dim data2

Dim data3

 

data1 = "blah"

data2 = "blah"

data3 = "blah"

 

This is very wasteful, I know.  But, I can not figure out why these so called phantom double quotes keep injecting themselves into my code.

 

Any ideas?

 

Thanks in advance!

  • I figured out the problem.

     

    The variables were global in script #1.  I passed them into script #2 from script #1.

     

    In script #2, I had to make valid json for a "POST" command like so:

    postData = "{""username"": " & username & ", ""password"": " & password & "}"

     

    This is valid json.  I checked it using json lint: http://jsonlint.com/

     

    However, the strange thing here is that when I leave script #2, those double quotes follow the variable.  So, username first equals "user@domain.com" in script #1.  When execution focus of the project returns from script #2, back into script #1, username still equals ""user@domain.com""!!!

     

    I solved this by doing the following at the end of script #2, right before focus returns back to script #1:

     

    username = aqString.unquote(username)

     

    So, now, in script #1, I will not have extra double quotes anymore.

     

    But, the bigger question is why did the double quotes follow the variable from script #2 back into script #1.  I thought the scope of the variable would have died in script #2?  So, this is pass by reference the whole time then?

2 Replies

    • twhitehouse's avatar
      twhitehouse
      Contributor

      I figured out the problem.

       

      The variables were global in script #1.  I passed them into script #2 from script #1.

       

      In script #2, I had to make valid json for a "POST" command like so:

      postData = "{""username"": " & username & ", ""password"": " & password & "}"

       

      This is valid json.  I checked it using json lint: http://jsonlint.com/

       

      However, the strange thing here is that when I leave script #2, those double quotes follow the variable.  So, username first equals "user@domain.com" in script #1.  When execution focus of the project returns from script #2, back into script #1, username still equals ""user@domain.com""!!!

       

      I solved this by doing the following at the end of script #2, right before focus returns back to script #1:

       

      username = aqString.unquote(username)

       

      So, now, in script #1, I will not have extra double quotes anymore.

       

      But, the bigger question is why did the double quotes follow the variable from script #2 back into script #1.  I thought the scope of the variable would have died in script #2?  So, this is pass by reference the whole time then?