1

I Delete control array element using Unload and try to replace element using following code

Private Sub mnudelete_Click()
Dim i As Integer
MsgBox (SelectedItemIndex)
RoomIndex = SelectedItemIndex
Unload frmData.lblRoom(RoomIndex)
Unload frmData.brdrRoom(RoomIndex)
For i = SelectedItemIndex To NumberOfRooms
    lblRoom(i) = lblRoom(i + 1)
    brdrRoom(i) = brdrRoom(i + 1)
Next
NumberOfRooms = NumberOfRooms - 1
End Sub

but some error occurred, is it possible to perform delete in control array? help me plz :)

Anugrah
  • 39
  • 1
  • 11

1 Answers1

1

You can only remove controls in a Control Array if you added them at runtime (try to delete one that you added via the designer and you'll get an error). This code should work:

Unload lblRoom(RoomIndex)
Unload brdrRoom(RoomIndex)

From MSDN:

You can use the Unload statement to remove any control created with Load. However, you cannot use Unload to remove controls created at design time, regardless of whether or not they are part of a control array.

C-Pound Guru
  • 15,967
  • 6
  • 46
  • 67
  • 1
    To expand a bit on C-Pound's answer: if you want to dynamically create controls on your form, you can use the Load statement to add a duplicate of an existing control. There has to be at least one added at design time. – BobRodes Aug 10 '15 at 02:08