The code below creates Labels dynamically based on a vector, it happens that I did not succeed in trying to delete (destroy) these objects.
I tested the 'Nothing' and other features indicated, but none worked, that is, the Labels remain on the form. As in the application each project that is selected will have a different number of Labels to be created, I need to destroy them when changing the project (without changing or closing the form).
I submit the code below one of the attempts to destroy the Labels, but it did not work. One comment: I also tried to destroy the Labels created inside the creation routine (at the end of it) to test, but in this case it did not work either.
How do I do this?
Private Sub CriaLabels(ByVal QuantidadeDeLabels As Integer)
Dim i As Integer
Dim NewLabel(QuantidadeDeLabels-1) As Object
For i = 0 To QuantidadeDeLabels-1
Set NewLabel(i) = Me.Controls.Add("Forms.Label.1")
With NewLabel(i)
.Tag = "NewLabel" & (i-1) 'Usar no lugar de "Name"
.Caption = .Tag 'Name inicia do Label2 pois existe o Label1 no formulário
.Top = 50 * i
.Left = 50
End With
Next i
End Sub
Private Sub DestroiLabels(ByVal QuantidadeDeLabels As Integer)
Dim i As Integer
For i = 0 To QuantidadeDeLabels-1
NewLabel(i).Delete 'NÂO FUNCIONOU ASSIM!!!
Next i
End Sub