Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Weird Error

Weird Error

Scheduled Pinned Locked Moved Visual Basic
questiondatabasehelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Muntyness
    wrote on last edited by
    #1

    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

    O 1 Reply Last reply
    0
    • M Muntyness

      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

      O Offline
      O Offline
      OldWarhorse
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • O OldWarhorse

        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

        M Offline
        M Offline
        Muntyness
        wrote on last edited by
        #3

        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

        O 2 Replies Last reply
        0
        • M Muntyness

          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

          O Offline
          O Offline
          OldWarhorse
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • M Muntyness

            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

            O Offline
            O Offline
            OldWarhorse
            wrote on last edited by
            #5

            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. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups