Micro Focus QTP (UFT) Forums
A DotnetFactory question on Stacks - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: A DotnetFactory question on Stacks (/Thread-A-DotnetFactory-question-on-Stacks)



A DotnetFactory question on Stacks - Parke - 09-27-2013

When I run the following code as a vbs file, it executes as expected.

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