Previous | Index | Next 

[PRB] Elements of control arrays can’t be referenced before being created

In VB6 it is legal to reference a control array element before actually creating it, as in this code:

        ' Command1 is a control array
        Set cmdTemp = Command1(1)
        Load cmdTemp
        cmdTemp.Caption = "New Button"
        cmdTemp.Visible = True

While VB Migration Partner handles most of control arrays’ features, this particular syntax cannot be automatically translated to VB.NET. You can solve this problem by changing the original VB6 code into:

        Load cmdTemp(1)
        Set cmdTemp = Command1(1)
        cmdTemp.Caption = "New Button"
        cmdTemp.Visible = True

or by means of a combination of pragmas:

        '## InsertStatement Command1.Load(1)
        Set cmdTemp = Command1(1)
        '## OutputMode Remarks, 1
        Load cmdTemp
        cmdTemp.Caption = "New Button"
        cmdTemp.Visible = True

 

Previous | Index | Next