borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Text generation in WORD)Next Topic (Minesweeper help with rnd()/randomization to set mines) New Topic New Poll Post Reply
AndreaVB Forum : VB General : How can re-index the dynamic controls array after remove an control item?
Poster Message
tuanhai
Level: Guest


icon How can re-index the dynamic controls array after remove an control item?   Archived to Disk

I have create a dynamic control array. For example: Create a text control name Text1 and set index = 0  -> Text1(0)
for i% = 1 to 5
   Load Text1(i)
   Text1(i).Left = Text1(i-1).Left
   Text1(i).Top = Text1(i-1).Top + Text1(0).Height + 20
   Text1(i).Visible = True
Next

Then I remove a control item from above array like:
Unload Text1(3)
What I need is the way to re-index that control array in order and also keep all properties of all controls. ie: the result control array I want is: Text1(i) where i = 0 .. 4 and all properties of the rest controls after control Text1(3): Text1(4) and Text1(5) are remain and shift to 0

Please give me a solution

Thanks in advance!

PS: Sorry for bad english

[Edited by admin on 05-04-2002 at 01:27 PM GMT]

05-04-2002 at 11:04 AM
| Quote Reply
MikeG
Level: Sage

Registered: 21-02-2003
Posts: 54
icon Re: How can re-index the dynamic controls array after remove an control item?   Archived to Disk

Hi,

This solution may be just a little too simple. Why not leave the control items in your array but just set the Visible property to False. This will disable them and avoid them getting in the way of your display. You can leave them in place and thus not disturb your code.

Mike

[Edited by admin on 05-04-2002 at 01:27 PM GMT]

05-04-2002 at 12:04 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: How can re-index the dynamic controls array after remove an control item?   Archived to Disk

Try this...


Private Sub Command1_Click()
    Dim i As Integer
    
    For i = 1 To 4
        Load Text1(i)
        Text1(i).Visible = True
        Text1(i).Top = Text1(i - 1).Top + Text1(i - 1).Height + 60
    Next
    
End Sub

Private Sub UnloadControl(Num As Long)
    Dim i As Integer

    For i = Num To Text1.UBound - 1
        Text1(i).Alignment = Text1(i + 1).Alignment
        Text1(i).BackColor = Text1(i + 1).BackColor
        Text1(i).BorderStyle = Text1(i + 1).BorderStyle
        Text1(i).Left = Text1(i + 1).Left
        Text1(i).Top = Text1(i + 1).Top
        Text1(i).Height = Text1(i + 1).Height
        Text1(i).Width = Text1(i + 1).Width
        Text1(i).Text = Text1(i + 1).Text
        Text1(i).Enabled = Text1(i + 1).Enabled
        '...and all other properties
    Next
    Unload Text1(Text1.UBound)
End Sub

Private Sub Command2_Click()
    UnloadControl 1
End Sub





[Edited by admin on 10-04-2002 at 01:18 PM GMT]

____________________________
AndreaVB

05-04-2002 at 12:10 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
tuanhai
Level: Guest

icon Re: How can re-index the dynamic controls array after remove an control item?   Archived to Disk

Many Thanks for your answer.
Your solution is shift back (copy all properies) to previous by 1 and finally delete the last control. My control is not simple as TextBox, it is a UserControl with many properties. Another question is: Is there any fast way to copy all properties to another control with the same type (Not .Text = .Text, .Left = .Left,...)

anyway, your answer is satisfy my need. Thanks alot!

06-04-2002 at 01:12 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: How can re-index the dynamic controls array after remove an control item?   Archived to Disk

Some times you can do this:

  Set FirstControl = SecondControl

But it doesn't work for everything, and if it does work, it may just set 1 property, not all of them (doesn't work for text boxes and the like, but may for custom controls)

08-04-2002 at 12:14 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB General : How can re-index the dynamic controls array after remove an control item?
Previous Topic (Text generation in WORD)Next Topic (Minesweeper help with rnd()/randomization to set mines) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder