Deletion of a control array item question 
Author Message
 Deletion of a control array item question

Hello,

I am currently working on a project that involves creation of a control
array at run time. For the time being, the control array is consisted of
textbox controls. I have so far succeeded in creating and loading the
control array, however I am facing problems that deal with the removal of an
item from the control array.

Specifically, say that the control array consists of 5 controls, indexed 0
to 4. Let's suppose that I want to remove the second element, with index 1.
I use the Unload element_array[1] call. Next, before the form is refreshed,
I set the Visible property of each element to true. However, the second
element of the array does not exist anymore, and access to the Visible
property fails, returning error indicating that the specific element does
not exist.

Is it possible that the control array be re-indexed after the deletion? In a
way that would resemble a shift of the elements in the array? It seems that
I cannot do much about that, due to the read-only limitation of the control
array...

Any hints would be greatly appreciated,

Thank you in advance,

Regards,

Thomas Kalogiannis



Fri, 05 Mar 2004 21:34:49 GMT  
 Deletion of a control array item question

Quote:
> Is it possible that the control array be re-indexed after the deletion?

No, you can't reindex the array. Instead of using the index use For Each:

Dim C as Control

For Each C In MyCtlArray
    C.Visible = False
Next

--
Eduardo A. Morcillo
http://www.domaindlx.com/e_morcillo



Fri, 05 Mar 2004 23:14:20 GMT  
 Deletion of a control array item question
You could also check if the control exists using
array(i) is nothing or just put some code to catch and
ignore errors.

Peter

Quote:
>-----Original Message-----
>Hello,

>I am currently working on a project that involves

creation of a control
Quote:
>array at run time. For the time being, the control array
is consisted of
>textbox controls. I have so far succeeded in creating and
loading the
>control array, however I am facing problems that deal

with the removal of an
Quote:
>item from the control array.

>Specifically, say that the control array consists of 5
controls, indexed 0
>to 4. Let's suppose that I want to remove the second

element, with index 1.
Quote:
>I use the Unload element_array[1] call. Next, before the
form is refreshed,
>I set the Visible property of each element to true.
However, the second
>element of the array does not exist anymore, and access
to the Visible
>property fails, returning error indicating that the

specific element does
Quote:
>not exist.

>Is it possible that the control array be re-indexed after
the deletion? In a
>way that would resemble a shift of the elements in the

array? It seems that
Quote:
>I cannot do much about that, due to the read-only

limitation of the control
Quote:
>array...

>Any hints would be greatly appreciated,

>Thank you in advance,

>Regards,

>Thomas Kalogiannis

>.



Sat, 06 Mar 2004 18:49:12 GMT  
 Deletion of a control array item question
Actually, you CAN re-index the controls. Take a look at the example below:

Private Sub Command1_Click()

Dim iIdx    As Integer

    If Text1.UBound >= 2 Then
        For iIdx = 2 To Text1.UBound - 1
            'Move Text1(iIdx) to Text1(iIdx + 1)'s position
            Text1(iIdx).Move Text1(iIdx + 1).Left, Text1(iIdx + 1).Top
            'Make Text1(iIdx) the same as Text1(iIdx + 1)
            Text1(iIdx) = Text1(iIdx + 1)
        Next
        'Unload the last TextBox
        Unload Text1(Text1.UBound)
        'Just to show that it actually works.
        For iIdx = Text1.LBound To Text1.UBound
            Text1(iIdx).Text = "Text1(" & CStr(Text1(iIdx).Index) & ")"
        Next
    End If

End Sub



Quote:
> > Is it possible that the control array be re-indexed after the deletion?

> No, you can't reindex the array. Instead of using the index use For Each:

> Dim C as Control

> For Each C In MyCtlArray
>     C.Visible = False
> Next

> --
> Eduardo A. Morcillo
> http://www.domaindlx.com/e_morcillo



Thu, 11 Mar 2004 07:25:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Each item in an array in an array of controls

2. Cant refer to control array item in the controls collection

3. How do I ban permanently deletion of the deleted items folder

4. Detecting the deletion of an item from a custom public folder

5. multiple item input and deletion

6. number of items in control array

7. Adding elements to a control array of Menu items with subMenus at Run time

8. How do I call a procedure that's executes a control array item

9. Create Control Array and add item at run time

10. "Disappearing" items of array controls

11. # of items in Control Array?

12. # of items in Control Array?

 

 
Powered by phpBB® Forum Software