Weird bug

H

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
 
S

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?
 
H

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 said:
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 :)
 
F

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.
 
C

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
 
H

Harry

Family Tree Mike said:
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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top