Results 1 to 11 of 11

Thread: [RESOLVED] [2008] error handling

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Resolved [RESOLVED] [2008] error handling

    When I run my program I will get an error every now and then, it is error code 5. According to http://support.microsoft.com/kb/146864 error code 5 is : Invalid procedure call. I also get these exceptions in the output window:



    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll

    does anyone know what this is and how to fix it? I have tried try/catch block (not very good at it but i tried) and on error goto, but that didn't work to well except for finding the error code number.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] error handling

    Are you using VBA? If not then that link you provided is irrelevant. To have any idea of what the issue is and how to fix it we'd have to have a far clearer picture of what you're doing, i.e. see your code and note the specific line that throws the exception.

    As for the other exceptions, this concept has been covered several times on the forum in the past. A first chance exception message in the debugger means an exception has been thrown somewhere in code. It may be your code or it may be system code. Exceptions are allowed to be thrown. If the debugger doesn't break then that means that the exception was handled, either in your code or in system code.

    The thing is, it's a good idea to establish whether those exceptions ARE being thrown in your code or in system code. If it's in your code then you need to make sure that it's not an indication that your code is flawed. You should determine whether it's possible to avoid the exception being thrown and, if so, alter your code accordingly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] error handling

    Oops, i am NOT using VBA I don't see how I missed that. As for the code that causes the error all i know is that it is in here:

    Code:
    Dim result, result2, result3, area As String
            area = "317"
            TextBox2.Text = browser.DocumentText
            If ComboBox3.Text = "Avon" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Bartlett" Then
                area = "(630)"
            End If
            If ComboBox3.Text = "Brownsburg" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Carmel" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Cicero" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Clayton" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Coatesville" Then
                area = "(812)"
            End If
            If ComboBox3.Text = "Cortland" Then
                area = "(607)"
            End If
            If ComboBox3.Text = "Danville" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Fishers" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Indianapolis" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Jamestown" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Lebanon" Then
                area = "(765)"
            End If
            If ComboBox3.Text = "Menomonie" Then
                area = "(715)"
    
            End If
            If ComboBox3.Text = "Mulberry" Then
                area = "(765)"
    
            End If
            If ComboBox3.Text = "North Salem" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Pittsboro" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Plainfield" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Speedway" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Troy" Then
                area = "(812)"
            End If
            If ComboBox3.Text = "Venice" Then
                area = "(941)"
            End If
            If ComboBox3.Text = "West Lafayette" Then
                area = "(765)"
            End If
            If ComboBox3.Text = "Westfield" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Whitestown" Then
                area = "(317)"
            End If
            If ComboBox3.Text = "Zionsville" Then
                area = "(317)"
    
            End If
    
            result = TextBox2.Text.IndexOf(area)
            If result <> -1 Then
                result = TextBox2.Text.Substring(area, 17)
                result2 = result.Remove(5, 3)
                result3 = result2.Remove(8, 1)
                TextBox1.Text = result3
            Else
                TextBox1.Text = "no data found."
                MsgBox("There is an error in the address that was searched")
            End If
    I know this because whenever I click this button on the third record in my DB it gives me my error. if this isnt clear enough i can just upload my project. But i must warn you my code is not very friendly.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] error handling

    We need more information. You say that the error occurs on the third record in your database. What data does that record contain? Which line throws the exception? What's the type of the exception? What's the error message?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] error handling

    the jpg is the only thing that lets me know that i have gotten an error. that just forces the program to close and vb acts normally as if i had hit the stop button. the record in my data base that causes the error is:

    Mailing Address Owner Name Mailing City Mailing State Mailing Zip
    1015 Summer Hill Pistoia, Frank J & Cynthia A Carmel IN 46032

    (sorry if it is out of alignment)
    Attached Images Attached Images  

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] error handling

    You need to debug your code. Place a break point at the top of the code and then step through it line by line. You can then determine what the last line of code that gets executed in your app is. You can also determine what the values of your variables are at that point. You, and we, will then likely have a far better idea of what we're looking for.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] error handling

    Code:
    result2 = result.Remove(5, 3)
    that is the line of code that causes the error. i think that the error is caused by result being to short so it can't start at the fifth character because result = 2052. now i need to figure out why it is not the full 17 digits i told it to search for...

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: [2008] error handling

    Set a breakpoint on the line and use Shift+F9 (or just the tooltip) to see what is in the variable.

    In that line, you are removing something from result, and result was built with a substring of textbox, but the substring is really odd. It sure doesn't look like the first argument to Substring should be area, since area is always set to be a five character string holding an area code. I suspect you meant to start from the point returned by IndexOf.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] error handling

    yes that is where i want to start my search. so how would i want to start my search after the area variable? i am kinda new to the searching string functions. thanks for your help this is starting to go back up hill

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: [2008] error handling

    Well, you get the index of Area, but that should be the index of the first character of the first instance of area in the string. Since area looks like it is always five characters long, the place you want to start the substring from is result+5.

    Except that I see that result is a string, in which case, this line:

    result = TextBox2.Text.IndexOf(area)

    will only compile with Option Strict OFF, which is definitely not a good idea, especially in this case. However, turning it on will probably give you plenty of other things to fix. Those fixes are worth doing (I just finished doing the same thing for one of my old projects, written before I had seen the light), because you will find other subtle bugs, and you will get a significant performance increase....well, maybe not so significant. I measured about a 30% increase in once case, but if everything seems to be happening instantly, as is the case with most apps, then 30% of 0 is still 0. No big gain from the users perspective.

    So you will need an integer to hold the value returned from that statement rather than Result, which should remain a string. If that integer is called I, then the substring line should look something like this:

    result = TextBox2.Text.Substring(I+5,17)

    I'm not entirely sure whether the 17 is strictly necessary, but that's up to you.
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] error handling

    thanks i got it working whith help from you now my project is almost done.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width