09-27-2013, 11:38 PM
When I run the following code as a vbs file, it executes as expected.
When I execute the script in QTP by altering the comment lines, I am informed that the object in the line "For Each Itm in objStack" is not a collection.
Also in QTP, for the "Join" line, the error message is "Type mismatch: 'Join' "
What am I doing wrong? Do I need to somehow use ICollection?
I guess part of my expectation has been if dotnet could be written in VBscript, then changing "CreateObject" to "DotNetFactory.CreateInstance" and presto, the code would execute.
Thanks for any and all help,
Parke
Code:
Set objStack = CreateObject("System.Collections.Stack")
'Set objStack = DotNetFactory.CreateInstance("System.Collections.Stack")
''Adding elements in Stack
objStack.Push "Item_1"
objStack.Push "Item_2"
objStack.Push "Item_3"
objStack.Push "Item_4"
' 'Iterate through each element of Stack
For Each Itm In objStack
'Print Item
msgbox Itm
Next
msgbox "stack count = " & stack.count
' 'Convert Stack to Array
'Print Join(objStack.ToArray, ",") ' 'output: Item_4,Item_3,Item_2,Item_1
msgbox Join(objStack.ToArray, ",")
When I execute the script in QTP by altering the comment lines, I am informed that the object in the line "For Each Itm in objStack" is not a collection.
Also in QTP, for the "Join" line, the error message is "Type mismatch: 'Join' "
What am I doing wrong? Do I need to somehow use ICollection?
I guess part of my expectation has been if dotnet could be written in VBscript, then changing "CreateObject" to "DotNetFactory.CreateInstance" and presto, the code would execute.
Thanks for any and all help,
Parke