Home All Groups Group Topic Archive Search About
Author
22 Nov 2007 10:38 PM
Harry
Hi All

I have this weird bug in the code below:

Dim temp As String = oAction.ActionType.ToString

For Each ctl As Control In Me.Controls

    If ctl.Tag IsNot Nothing Then

        ctl.Visible = ctl.Tag.ToString.Contains(temp)   '<------error here

        ctl.Enabled = ctl.Visible

    End If

Next

The error is: IndexOutOfRangeException  (Index -1 does not have a value)

I have a number of controls on the form that are visible depending on the
value I put in the tag property

Author
22 Nov 2007 11:16 PM
Stephany Young
That's what happens when you try to cut some code the day before a General
Election :)

Do you have Option Strict turned on.

If not then turn it on. I STRONG RECOMMEND that you turn Option Strict on
(and leave it on) for ALL VB.NET projects unless you have a specific
temporary need to turn it off. There are some circumstances involving late
binding where itcan be adventageous to turn it off it specific code files
but those circumstances are few and far between.

Now, we've got the advertisement out of the way ....

When the line in question is reached:

  what is the actual value of temp?

  is the actual value of temp match what you expect it to be?

  what is the actual value of ctl.Tag?

  is the actual value of ctl.Tag match what you expect it to be?



Show quoteHide quote
"Harry" <harryNoSpam@ffapaysmart.com.au> wrote in message
news:OttkShVLIHA.1208@TK2MSFTNGP05.phx.gbl...
> Hi All
>
> I have this weird bug in the code below:
>
> Dim temp As String = oAction.ActionType.ToString
>
> For Each ctl As Control In Me.Controls
>
>    If ctl.Tag IsNot Nothing Then
>
>        ctl.Visible = ctl.Tag.ToString.Contains(temp)   '<------error here
>
>        ctl.Enabled = ctl.Visible
>
>    End If
>
> Next
>
> The error is: IndexOutOfRangeException  (Index -1 does not have a value)
>
> I have a number of controls on the form that are visible depending on the
> value I put in the tag property
>
>
>
>
Author
23 Nov 2007 1:14 AM
Harry
Thank you for your reply. Please find my comments inline.

I am using VS2008 Pro (released to MSDN subscribers a few days ago),
however, the bug was present in VS2005 as well.

Harry

"Stephany Young" <noone@localhost> wrote in message
news:O6tcF3VLIHA.1168@TK2MSFTNGP02.phx.gbl...
> That's what happens when you try to cut some code the day before a General
> Election :)
>
> Do you have Option Strict turned on.

Most certainly do..its my best friend :)

>
> If not then turn it on. I STRONG RECOMMEND that you turn Option Strict on
> (and leave it on) for ALL VB.NET projects unless you have a specific
> temporary need to turn it off. There are some circumstances involving late
> binding where itcan be adventageous to turn it off it specific code files
> but those circumstances are few and far between.
>
> Now, we've got the advertisement out of the way ....
>
> When the line in question is reached:
>
>  what is the actual value of temp?

3

>
>  is the actual value of temp match what you expect it to be?

3

>
>  what is the actual value of ctl.Tag?

12345789

>
>  is the actual value of ctl.Tag match what you expect it to be?
>

12345789

Show quoteHide quote
>
>
> "Harry" <harryNoSpam@ffapaysmart.com.au> wrote in message
> news:OttkShVLIHA.1208@TK2MSFTNGP05.phx.gbl...
>> Hi All
>>
>> I have this weird bug in the code below:
>>
>> Dim temp As String = oAction.ActionType.ToString
>>
>> For Each ctl As Control In Me.Controls
>>
>>    If ctl.Tag IsNot Nothing Then
>>
>>        ctl.Visible = ctl.Tag.ToString.Contains(temp)   '<------error here
>>
>>        ctl.Enabled = ctl.Visible
>>
>>    End If
>>
>> Next
>>
>> The error is: IndexOutOfRangeException  (Index -1 does not have a value)
>>
>> I have a number of controls on the form that are visible depending on the
>> value I put in the tag property
>>
>>
>>
>>
>
Author
23 Nov 2007 2:41 AM
Family Tree Mike
Based on your information, the control should be set to visible and enabled,
in that order.  If you are not trapping some error in the handler for setting
a control to visible, I think it could pop up where you are showing this
error.  This is a guess though, because the code you have submitted looks
perfectly resonable.

Show quoteHide quote
"Harry" wrote:

> Thank you for your reply. Please find my comments inline.
>
> I am using VS2008 Pro (released to MSDN subscribers a few days ago),
> however, the bug was present in VS2005 as well.
>
> Harry
>
> "Stephany Young" <noone@localhost> wrote in message
> news:O6tcF3VLIHA.1168@TK2MSFTNGP02.phx.gbl...
> > That's what happens when you try to cut some code the day before a General
> > Election :)
> >
> > Do you have Option Strict turned on.
>
> Most certainly do..its my best friend :)
>
> >
> > If not then turn it on. I STRONG RECOMMEND that you turn Option Strict on
> > (and leave it on) for ALL VB.NET projects unless you have a specific
> > temporary need to turn it off. There are some circumstances involving late
> > binding where itcan be adventageous to turn it off it specific code files
> > but those circumstances are few and far between.
> >
> > Now, we've got the advertisement out of the way ....
> >
> > When the line in question is reached:
> >
> >  what is the actual value of temp?
>
> 3
>
> >
> >  is the actual value of temp match what you expect it to be?
>
> 3
>
> >
> >  what is the actual value of ctl.Tag?
>
> 12345789
>
> >
> >  is the actual value of ctl.Tag match what you expect it to be?
> >
>
> 12345789
>
> >
> >
> > "Harry" <harryNoSpam@ffapaysmart.com.au> wrote in message
> > news:OttkShVLIHA.1208@TK2MSFTNGP05.phx.gbl...
> >> Hi All
> >>
> >> I have this weird bug in the code below:
> >>
> >> Dim temp As String = oAction.ActionType.ToString
> >>
> >> For Each ctl As Control In Me.Controls
> >>
> >>    If ctl.Tag IsNot Nothing Then
> >>
> >>        ctl.Visible = ctl.Tag.ToString.Contains(temp)   '<------error here
> >>
> >>        ctl.Enabled = ctl.Visible
> >>
> >>    End If
> >>
> >> Next
> >>
> >> The error is: IndexOutOfRangeException  (Index -1 does not have a value)
> >>
> >> I have a number of controls on the form that are visible depending on the
> >> value I put in the tag property
> >>
> >>
> >>
> >>
> >
>
>
>
Author
23 Nov 2007 10:12 PM
Harry
Show quote Hide quote
"Family Tree Mike" <FamilyTreeM***@discussions.microsoft.com> wrote in
message news:90315D59-9656-4534-8BFC-972BC498BDD2@microsoft.com...
> Based on your information, the control should be set to visible and
> enabled,
> in that order.  If you are not trapping some error in the handler for
> setting
> a control to visible, I think it could pop up where you are showing this
> error.  This is a guess though, because the code you have submitted looks
> perfectly resonable.
>
> "Harry" wrote:
>
>> Thank you for your reply. Please find my comments inline.
>>
>> I am using VS2008 Pro (released to MSDN subscribers a few days ago),
>> however, the bug was present in VS2005 as well.
>>
>> Harry
>>
>> "Stephany Young" <noone@localhost> wrote in message
>> news:O6tcF3VLIHA.1168@TK2MSFTNGP02.phx.gbl...
>> > That's what happens when you try to cut some code the day before a
>> > General
>> > Election :)
>> >
>> > Do you have Option Strict turned on.
>>
>> Most certainly do..its my best friend :)
>>
>> >
>> > If not then turn it on. I STRONG RECOMMEND that you turn Option Strict
>> > on
>> > (and leave it on) for ALL VB.NET projects unless you have a specific
>> > temporary need to turn it off. There are some circumstances involving
>> > late
>> > binding where itcan be adventageous to turn it off it specific code
>> > files
>> > but those circumstances are few and far between.
>> >
>> > Now, we've got the advertisement out of the way ....
>> >
>> > When the line in question is reached:
>> >
>> >  what is the actual value of temp?
>>
>> 3
>>
>> >
>> >  is the actual value of temp match what you expect it to be?
>>
>> 3
>>
>> >
>> >  what is the actual value of ctl.Tag?
>>
>> 12345789
>>
>> >
>> >  is the actual value of ctl.Tag match what you expect it to be?
>> >
>>
>> 12345789
>>
>> >
>> >
>> > "Harry" <harryNoSpam@ffapaysmart.com.au> wrote in message
>> > news:OttkShVLIHA.1208@TK2MSFTNGP05.phx.gbl...
>> >> Hi All
>> >>
>> >> I have this weird bug in the code below:
>> >>
>> >> Dim temp As String = oAction.ActionType.ToString
>> >>
>> >> For Each ctl As Control In Me.Controls
>> >>
>> >>    If ctl.Tag IsNot Nothing Then
>> >>
>> >>        ctl.Visible = ctl.Tag.ToString.Contains(temp)   '<------error
>> >> here
>> >>
>> >>        ctl.Enabled = ctl.Visible
>> >>
>> >>    End If
>> >>
>> >> Next
>> >>
>> >> The error is: IndexOutOfRangeException  (Index -1 does not have a
>> >> value)
>> >>
>> >> I have a number of controls on the form that are visible depending on
>> >> the
>> >> value I put in the tag property
>> >>
>> >>
>> >>
>> >>
Found the problem! I think this is a MS bug

I had this line before the piece of code I showed you:
Me.ActionRequestBindingSource.SuspendBinding()

I put the line of code after the for/next loop instead and the problem has
disappeared......Yahoo
Author
23 Nov 2007 7:19 PM
Cor Ligthert[MVP]
Harry,

What is me, if that does not contain a control, then your result will be -1
that is not a bug, you have to test before that.

However don't ask here with bugs about your program, we see bugs as bugs in
Visual Studio and then become confused.

Thank you in advance.

Cor