Question

With refactoring some old VB6 code I stumbled upon some really weird behavior. When I try to set the DragMode property of an element of a control array, the compiler tells me 'Method or data member not found' when I separate this control from its array.

See my example below where 'myControl' is nothing else but a User Control with a Textbox in it. And where 'Controls' is a Control Array with myControls in it. The first loop works and the second one doesn't.

Dim i As Integer
Dim ctrl As myControl

For i = 0 To 2
    myControls(i).DragMode = vbAutomatic
Next i

For Each ctrl In myControls
    ctrl.DragMode = vbAutomatic
Next

Update:

With thanks to @wqw I got the for each loop working. The code that works for me now looks something like this:

Dim ctrlExt As VBControlExtender
Dim ctrl As myControl

For Each ctrlExt In myControls

    Set ctrl = ctrlExt

    ctrlExt.DragMode = vbAutomatic
    ctrl.SpecificProperty = "Test"
Next
Was it helpful?

Solution

Try Dim ctrl As VBControlExtender

This works

Dim i As Integer
Dim ctrl As VBControlExtender

For Each ctrl In Controls
    ctrl.DragMode = vbAutomatic
Next

For i = MyControls.LBound To MyControls.UBound
    MyControls(i).DragMode = vbAutomatic
Next i
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top