Note that there are some explanatory texts on larger screens.

plurals
  1. POStringify a method call in VBScript
    primarykey
    data
    text
    <p>I'm currently working every day with QuickTest Professional 11, which uses VBScript behind the scenes. Lately, I've started developing some of my own functions to handle common situations. I'm pretty new to VBscript, most of my programming experience is in C and Python.</p> <p>I'm trying to implement Python's Try/Except in VBScript, mostly to wrap around actions like clicking links or selecting values from dropdown boxes. Here's what I have so far:</p> <pre><code>Class cls_ErrorHandler Private bWasError Private Sub Class_Initialize() bWasError = False End Sub Private Sub IsErr If Err.Number &lt;&gt; 0 Then bWasError = True Else bWasError = False End If Err.Clear End Sub ' If the command fails, set bWasError Public Sub Try(strCommandToTry) On Error Resume Next Execute(strCommandToTry) me.IsErr On Error Goto 0 End Sub Public Sub Except(strCommandInCaseOfError) If bWasError Then Execute(strCommandInCaseOfError) End If bWasError = False End Sub End Class </code></pre> <p>I'd like to be able to write things like this:</p> <pre><code>Set oErrorHandler = New cls_ErrorHandler oErrorHandler.Try(Stringify(Browser("Browser Name").Page("Page Name").WebCheckBox("Checkbox Name").Set "ON" oErrorHander.Except(Stringify(Browser("Browser Name").Page("Page Name").WebButton("Save").Click)) </code></pre> <p>As far as I can tell, there really isn't any nice way to pass a function as an argument to another function in VBScript. The best way seems to be to pass a string containing the name of a function, and then feed that string into Execute() or Eval(). Objects in QuickTest Professional tend to have lots of quotation marks, so escaping them all by hand would make the code unreadable.</p> <p>In C, I'd use something like this:</p> <pre><code>#define Stringify(obj) #obj </code></pre> <p>and it would be done... but nothing like that seems to exist in VBScript. Is there any way to implement this? Is there anything in VBScript that takes an object as its input and returns a string representation of that object's name? Would it be possible to write a DLL in C/C# that would provide this kind of functionality?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload