Forum Discussion

Natasha_2012's avatar
Natasha_2012
Contributor
8 years ago

how to store a string containing escape/exclaim mark/tilde characters using vbscript

Hi Everyone

I need to store the below string into a variable and type this variable value into a text, but I cannot.  TestComplete will be stalled when typing half way
strText = "("\(troub\*e\) sh\*t") AND ("\{troub\*e\} sh\*t") AND ("\[troub\*e\] sh\*t") AND ("\<troub\*e\> sh\*t") AND ("\@troub\*e \! sh\*t") AND ("\troub\*e\~ sh\*t") AND ("\^troub\*e\& sh\*t")"

 

However, I type the above string manually and record my typing, I see that TestComplete is recording the above string as

(""\(troub\*e\) sh\*t"") AND (""\{troub\*e\} sh\*t"") AND (""\[[troub\*e\] sh\*t"") AND (""\<troub\*e\> sh\*t"") AND (""\@troub\*e \!! sh\*t"") AND (""\troub\*e\~~ sh\*t"") AND (""\^^troub\*e\& sh\*t"")

 

As I have mentioned above, I need to store the above string into a data file, whenever my script is running, it will read that data file, load the string into strText, then my textFieldObj.Keys(strText)

 

So what should I do here to make TestComplete be able to key in successful my string as look like it see that string a bit different

 

Kind Regards

Nat

3 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi Natasha,

     

    Simulating of some keys is more tricky.

    E.g. to simulate "[" symbol you should use constant "[[", to simulate "^" - use "^^"

    "\t" will be recognized as a tab-key escape code, so you need to use another escape symbol to simulate it literally: "\\t". 

     

    Please refer to TC documentation >>

     

    You variable should be assigned as:

     

    strText = '"("\(troub\*e\) sh\*t") AND ("\{troub\*e\} sh\*t") AND ("\[[troub\*e\] sh\*t") AND ("\<troub\*e\> sh\*t") AND ("\@troub\*e \!! sh\*t") AND ("\\troub\*e\~~ sh\*t") AND ("\^^troub\*e\& sh\*t")"'
    

     

  • shankar_r's avatar
    shankar_r
    Community Hero

    You can try something like which will work for all letters that you have.

     

    yourObject.Click()

    WshShell.SendKeys(str_Input)

    • Natasha_2012's avatar
      Natasha_2012
      Contributor

      SmartBear reply the way to simulate the key for this "("\(troub\*e\) sh\*t") AND ("\{troub\*e\} sh\*t") AND ("\[troub\*e\] sh\*t") AND ("\<troub\*e\> sh\*t") AND ("\@troub\*e \! sh\*t") AND ("\troub\*e\~ sh\*t") AND ("\^troub\*e\& sh\*t") " as following:

       

      Call Project.Variables.Var1 = "(""\(troub\*e\) sh\*t"") AND (""\{troub\*e\} sh\*t"") AND (""\[[troub\*e\] sh\*t"") AND (""\<troub\*e\> sh\*t"") AND (""\@troub\*e \!! sh\*t"") AND (""\troub\*e\~~ sh\*t"") AND (""\^^troub\*e\& sh\*t"")"
       
      var strText = Project.Variables.VariableByName("Var1");

      Call testObj.Keys(strText )