Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Im having a problem with my Code

[CODE]

Dim i As Short

If MDIForm1.ActiveMdiChild Is Nothing Then Exit Sub

For i = 0 To Controls.Count() - 1

Select Case TypeName(CType(Controls(i), Object))
Case "TextBox"
CType(Controls(i), Object).Text = CType(MDIForm1.ActiveMdiChild.Controls(i), Object).Text
Case "Label"
CType(Controls(i), Object).Text = CType(MDIForm1.ActiveMdiChild.Controls(i), Object).Text ' It says Index 5 is out of range.
Parameter name: index


End Select
Next i
[657 byte] By [InoS] at [2007-11-11 8:03:32]
# 1 Re: Im having a problem with my Code
can someone please help
InoS at 2007-11-11 21:48:05 >
# 2 Re: Im having a problem with my Code
One issue I think is in this part:

CType(MDIForm1.ActiveMdiChild.Controls(i), Object).Text

You are trying to access the i'th control on the active MDI child but the variable i is an index to a control on the MDI parent, which in this code you named MDIForm1.

But of course that is assuming you are running this code from inside MDIForm1.

If I may ask, what are you trying to do with this code? Also in which form is this code running?
AdamP at 2007-11-11 21:49:05 >
# 3 Re: Im having a problem with my Code
Hi,
I agree with Adam. The issue is that you are referring to 2 different forms.
You define to loop through all controls for example on formA (5 controls for ex) with the variable i. You use the same variable to compare the controls of formB=child I assume(4 controls for example).

What happens => i = 4 => accessing control 5th control on formA
=> trying to access 5th control on formB => not available, index out of range

Hope this clears things up.
Benjamin at 2007-11-11 21:50:10 >