Weird Error
-
First off, let me just say that this question is just for information purposes. (I'm kinda curious as to why this is happening) I have a wierd error with the VB program I have access to here. The error is in the code and has to do with some of the standard tabControl methods. What happens is that if that there is a method that returns an in depending on what letter is put into it. The returned int is then used to select which tab page is shown by the control. To get the code to work it goes something like this: Dim index As New Integer tabIndex = Groups.ConvertToNumber(Attribute.Group) If Not Groups.ConvertToNumber(Attribute.Group) = -1 Then FunctionPicker.SelectedTab = FunctionPicker.TabPages(tabIndex) End If The above code works. However if I change the code to this: If Not Groups.ConvertToNumber(Attribute.Group) = -1 Then FunctionPicker.SelectedTab = FunctionPicker.TabPages(Groups.ConvertToNumber(Attribute.Group)) End If It no longer works, when it should. (And as far as I know worked in previous versions) Any idea as to why this happens? - Munty
-
First off, let me just say that this question is just for information purposes. (I'm kinda curious as to why this is happening) I have a wierd error with the VB program I have access to here. The error is in the code and has to do with some of the standard tabControl methods. What happens is that if that there is a method that returns an in depending on what letter is put into it. The returned int is then used to select which tab page is shown by the control. To get the code to work it goes something like this: Dim index As New Integer tabIndex = Groups.ConvertToNumber(Attribute.Group) If Not Groups.ConvertToNumber(Attribute.Group) = -1 Then FunctionPicker.SelectedTab = FunctionPicker.TabPages(tabIndex) End If The above code works. However if I change the code to this: If Not Groups.ConvertToNumber(Attribute.Group) = -1 Then FunctionPicker.SelectedTab = FunctionPicker.TabPages(Groups.ConvertToNumber(Attribute.Group)) End If It no longer works, when it should. (And as far as I know worked in previous versions) Any idea as to why this happens? - Munty
Disregard previous reply if you saw it... Eyes playing tricks on me. Don't know. But here's my 2 cents. We don't really know what ".ConvertToNumber" returns. We're assuming it's a user-written function and returns something numeric, but... But the whole thing becomes moot if the code is written properly. Suggestion: To make the code more efficient, don't execute the expensive function more than once if you can help it. Execute it, get the validated results in tabIndex, (preferably within a Try block, using System.Convert), so you know exactly what you're dealing with, and then just use the index. Dave
-
Disregard previous reply if you saw it... Eyes playing tricks on me. Don't know. But here's my 2 cents. We don't really know what ".ConvertToNumber" returns. We're assuming it's a user-written function and returns something numeric, but... But the whole thing becomes moot if the code is written properly. Suggestion: To make the code more efficient, don't execute the expensive function more than once if you can help it. Execute it, get the validated results in tabIndex, (preferably within a Try block, using System.Convert), so you know exactly what you're dealing with, and then just use the index. Dave
Hi there. The ConvertToNumber always returns a number. The number returned will always be from between -1 and 7. (-1 being the Error number) I've been stepping through the program with Visual Studios debugger, So I can tell ya that it is definately returning a number. For the testing I was doing, it always returned the number 2. However if I looked at the FunctionPicker.SelectedTab it always states that it contains nothing. But it always works correctly if I put it into an pass the results of ConvertToNumber into an integer before passing it into the TabPages method. Hence why I'm calling it a wierd bug :) - Munty
-
Hi there. The ConvertToNumber always returns a number. The number returned will always be from between -1 and 7. (-1 being the Error number) I've been stepping through the program with Visual Studios debugger, So I can tell ya that it is definately returning a number. For the testing I was doing, it always returned the number 2. However if I looked at the FunctionPicker.SelectedTab it always states that it contains nothing. But it always works correctly if I put it into an pass the results of ConvertToNumber into an integer before passing it into the TabPages method. Hence why I'm calling it a wierd bug :) - Munty
That is definitely a puzzler. If I get some time later tonight I will set one up and see if I can reproduce it. Dave
-
Hi there. The ConvertToNumber always returns a number. The number returned will always be from between -1 and 7. (-1 being the Error number) I've been stepping through the program with Visual Studios debugger, So I can tell ya that it is definately returning a number. For the testing I was doing, it always returned the number 2. However if I looked at the FunctionPicker.SelectedTab it always states that it contains nothing. But it always works correctly if I put it into an pass the results of ConvertToNumber into an integer before passing it into the TabPages method. Hence why I'm calling it a wierd bug :) - Munty
Munty - Couldn't reproduce it. I set up a form with a tab control with 8 pages, various overloaded functions to return integers and singles (which I then cast to Int) etc, buttons to set the preconditions and call each scenario, ... Got the right tab selected every time. You're right. That's a weird bug. :)