What is the best way to determine if a particular QTP step could be converted to a function?
For example the recorded statement below
Browser("Administrator Login").Page("ABC Application").Frame("mainFrame_8").WebTable("ABC") .Check CheckPoint("ABC")
cannot be assigned to a variable as is. It requires an extra set of parantheses by the checkpoint Checkpoint("ABC")
so it will look like this
chptpassfail=Browser("Administrator Login").Page("ABC Application").Frame("mainFrame_8").WebTable("ABC") .(Check CheckPoint("ABC"))
I could not find a good set of rules as to what can return a value and what does not return a value anywhere in the QTP manuals. My current quick and "dirty" solution is I assign the keyword view to a variable and try to move on the next line if the QTP interface gives me a syntax error then I start putting PARANTHESES and sometime, I get luck and sometimes I do not. There has to be a better systematic method of doing this. Note...note all Methods of objects is accepting parantheses. Believe me I tried.
Finally, I am an old school C programmer but I am struggling with VB script and object oriented programming at times.
If a method returns a value, then if you want to assign that value to a variable, you must use parens.
<font class="small">Code:</font><hr /><pre>Object.MethodThatReturnsAValue InputValue</pre><hr />
will execute the method with the input value, we just haven't bothered to collect the return value (that's why recorded QTP lines look like this).
Parentheses are required when you want to use the return value.
<font class="small">Code:</font><hr /><pre>ReturnedValue = Object.MethodThatReturnsAValue(InputValue)</pre><hr />
<font class="small">Code:</font><hr /><pre>If Object.MethodThatReturnsAValue(InputValue) = ExpectedValue Then ...</pre><hr />