3
votes

I just discovered here the 'built-in' Stacks and Queues available from VBA. The way it's written, I can't see the properties and methods of the Queue object.

Dim queue As Object
Set queue = CreateObject("System.Collections.Queue") 'Create the Queue

queue.Enqueue "Hello"   'VBE does not show the available properties and methods

So my question is: is there a reference I can use that will allow me to have early binding and benefit from the VBE autocomplete ? Something like:

Dim queue As System.Collections.Queue   'not working
1
There's no built-in Stacks and Queues available from VBA. Those are COM objects from the .Net framework which may be missing or unavailable depending on the setup. You can add mscorelib.dll to view the interfaces. - Florent B.

1 Answers

3
votes

The Stack and Queue are COM objects from the .Net framework, they cannot be used with early binding. (as mentioned by @Florent B. in the comments).

However, if you need to see the properties of the COM object, you can always take a look at the MSDN site (it is quite explicit there): https://msdn.microsoft.com/en-us/library/system.collections.queue(v=vs.110).aspx

Or open a Visual Studio and check from there, the IntelliSense. Pretty much anything written there works:

Public Sub TestMe()    
    Dim myArr  As Variant        
    With CreateObject("System.Collections.Queue")
        .Clear
        .Enqueue (1)
        .Enqueue (2)
        myArr = .toArray
    End With
    Debug.Print myArr(1)        
End Sub