|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Weird bugI 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 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 > > > > 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 Most certainly do..its my best friend :)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. > 3> 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? > 12345789> what is the actual value of ctl.Tag? > 12345789> 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 >> >> >> >> > 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 > >> > >> > >> > >> > > > > >
Show quote
Hide quote
"Family Tree Mike" <FamilyTreeM***@discussions.microsoft.com> wrote in Found the problem! I think this is a MS bugmessage 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 >> >> >> >> >> >> >> >> 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 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
Multithreading dilemma
How do you use GetProperty.SetValue with the index parameter? EventHandler for late-bound COM object How to check a string to see that it is a valid file name name parser How to change the name of multiple textboxes CD Burning with VB.NET Silly syntactic question Opening Folder Browse Dialog On Client Side Extension Methods in VB 2008 Express? |
|||||||||||||||||||||||