dcsimg
Results 1 to 13 of 13

Thread: [RESOLVED] is there any way to record program flow for error checking later?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Resolved [RESOLVED] is there any way to record program flow for error checking later?

    Our Clients sometimes complain about program not working in the desired way. We spent hours testing and sometimes are not able to find how that chance for error
    occurred. If there was any way to record the program flow it would have been easy. Its sometimes because there was an attempt to convert varchar to int. How can we achieve this?

    example:
    created variable x
    assigned 23 to x
    passed x to sub root()

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: is there any way to record program flow for error checking later?

    Quote Originally Posted by BlueFox View Post
    If there was any way to record the program flow it would have been easy.
    One of the Tips for Debugging is:

    Quote Originally Posted by MSDN
    Create a log file. If you cannot isolate the code or if the problem is erratic or if the problem only happens when compiled, then the debugging facility of Visual Basic will be less effective. In these situations you can create a log file which records the activity of your program. This will allow you to progressively isolate the location of the suspect code. Call the following procedure from various points in your program. You should pass in a string of text which indicates the current location of the code executing in your program. Read more...
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: is there any way to record program flow for error checking later?

    Code:
    Dim FN As Integer
      '
      '
    Private Sub Form_Load()
     RunLog "Form_Load"
      '
      '
      ' 
    End Sub
    
    Private Sub Sub1()
     RunLog "Enter Sub1"
      '
      '
      '
     RunLog "Exit Sub1"
    End Sub
    
    Private Sub Sub2()
     RunLog "Enter Sub2"
      '
      '
     RunLog "Exit Sub2"
    End Sub
      '
      '
    Private Sub RunLog(Info As String)
     FN = FreeFile()
     Open App.Path & "\run_log.txt" For Append As #FN
     Print #FN, Info
     Close #FN
    End Sub
    Last edited by jmsrickland; Aug 6th, 2013 at 01:50 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: is there any way to record program flow for error checking later?

    Another way is to use line numbers. This approach, however, is for catching run time errors only. It will not work for catching logic errors in which case you need to use the log file approach.

    Code:
    Dim FN As Integer
      '
      '
    Private Sub Form_Load()
     FN = FreeFile()
      '
      '
      ' 
      '
    End Sub
    
    Private Sub Sub1()
     On Error GoTo EH
    
     10  Dim s As String
     20  On Error GoTo errHandler
     30  s = "A" / 0
     40  s = "Hello      " & vbCrLf & "how are yo+_)(*&^%$#@!"  '
       '
     Exit Sub
    EH:
     RunLog "Sub1 Error " & Err.Number & " " & Err.Description & " Occurred on Line " & Erl
    End Sub
    
    Private Sub RunLog(Info As String)
     Open App.Path & "\run_log.txt" For Append As #FN
     Print #FN, Info
     Close #FN
    End Sub
    Last edited by jmsrickland; Aug 5th, 2013 at 01:24 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Re: is there any way to record program flow for error checking later?

    So you are saying that there is no automatic method to trace entire program flow without writing thousands of lines in my application? I might need to add one line to existing one line in all my programs then. Some body said about stack trace. How is it helpful?

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: is there any way to record program flow for error checking later?

    I don't think stack trace applies to VB. I'v heard of it in Java and C. I'm not even sure how it works in those languages but I suspect it has to do with debugging at an assembly like or low level but not sure.

    Wouldn't you think that if there is a better way than what has already been posted that MS would have it on their Web Site but all they have is what you see at the link Bonnie posted.

    There are ways to narrow it down somewhat but you at least have to have some idea where the problem is stemming from. If you have absolutely no idea at all or even the slightest hint then I'm afraid your limited to what has been presented.

    Try narrowing it down by putting trace points in only major areas first or areas where you might think the culprit lies and see if you can get it down to say from trace point 5 to trace point 15 for example.

    Put the call to RunLog() only at the entry to a few subs at a time. If problem doesn't occur in those then put the call in a few others. Do this little by little until you get it narrowed down to a few subs then you have at least something to work with on a smaller scale

    I have never written a program where I didn't have some idea, no matter how faint, where a problem is coming from. Now, if I didn't write the program then that's another story.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,022

    Re: is there any way to record program flow for error checking later?

    You can find in my signature a way of logging errors including a stack trace for debugging latter on, what you can also perform is to 'screenshot' the window when an error occurs so you can examine what data they have inputted, that is if they will allow you to do that.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,680

    Re: is there any way to record program flow for error checking later?

    Quote Originally Posted by BlueFox View Post
    Some body said about stack trace. How is it helpful?
    The Stack Trace is means of tracking the stack at the time of the exception. Unfortunately VB6 does not have a means of exposing the stack trace. Which means it's up to you to do it yourself (sucks, I know).
    In short the stack trace works like this: as you move from one method/function to another, the instruction point (along with any parameter data or anything else that needs to be passed over) gets pushed onto the stack. When an exception is encountered, the status of the stack is captured. This is the stack trace.

    Given this:
    Code:
    Sub Foo()
      bar() ' Call the Bar method
    End Sub
    
    Sub Bar()
    ' -- an exception happens here...
    end Sub
    If we have a sub, Foo that calls Bar, and an exception happens in Bar, then the stack trace will show (simplified):
    Code:
    Bar()
    Foo()
    It's a highly simplified version of the stack trace... but it shows the general concept.

    Code:
    Sub Foo()
      bar() ' Call the Bar method
    End Sub
    
    Sub Bar()
      moreFoo()
    end Sub
    
    Sub MoreFoo()
    'Exception happens here
    End Sub
    Now the stack trace looks like:
    Code:
    MoreFoo()
    Bar()
    Foo()

    Code:
    Sub Foo()
      bar() ' Call the Bar method
    End Sub
    
    Sub Bar()
      chuckNoirris()
      moreFoo()
    end Sub
    
    Sub MoreFoo()
    'Exception happens here
    End Sub
    
    Sub ChuckNorris()
    'Chuck Norris doesn't allow exceptions to happen here
    End Sub
    Gives us the same stack trace:
    Code:
    MoreFoo()
    Bar()
    Foo()
    That's because the call to ChuckNorris was successful, and so when the execution returned back to Bar, the stack "unwinds" (or more accurately it Pops the call to Chuck off the stack since it succeeded) and it continues with the call to moreFoo... where an exception happens.

    I think I have this all right, it's a highly simplified version of what happens, but should be sufficient for demonstrative purposes.

    ----------

    All that said... I've seen some tracers that use "push" and "pop" calls to track where they are...

    -- NOTE - I do not havce VB6 to try this one, so I'm shooting from the hip here, so it may need some changes to run properly....
    [code]
    Dim colStack as Collection

    Public Sub Push(subName as String)
    if colStack Is Nothing then
    set ColStack = New Collection
    end If

    colStack.Add subName
    end Sub

    public Sub Pop(subName as string)
    colStack.Remove subName
    end Sub

    Code:
    Sub Foo()
      Push "Foo"
      bar() ' Call the Bar method
      Pop "Foo"
    End Sub
    
    Sub Bar()
      Push "Bar"
      chuckNoirris()
      moreFoo()
      Pop "Bar"
    end Sub
    
    Sub MoreFoo()
      Push "moreFoo"
    'Exception happens here
      Pop "moreFoo"
    End Sub
    
    
    Sub ChuckNorris()
      Push "Chuck Norris" 'Dangerous call, be careful
    'Chuck Norris doesn't allow exceptions to happen here
      Pop "Chuck Norris" 'Another dangerous call
    End Sub
    Now, in your exception handler, all you need to do is examine the colStack collection to see where you are. NOTE - it's very basic and rudimentry and doesn't take into account calls in a recurrsive manner.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: is there any way to record program flow for error checking later?

    I don't see where those are going to do any better than the simple method pointed out by MS and what I showed in post 3 since it appears that you still need to make a call on entry and another call on exit of a sub which is one thing OP complained about. Also, from what I read it is only useful on exceptions and not on regular flow of code where the problem could be because of a logic error that does not throw an exception.
    Last edited by jmsrickland; Aug 6th, 2013 at 12:38 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,680

    Re: is there any way to record program flow for error checking later?

    Hey, I jsut said it was a way... not the best, jsut a way... I'll admit, that stack tracing in VB6 suxors big time... I spent I don't know how many hours doing the exact same blankity-blankity-blank-blank-blank think that the OP is experienceing... to make matters worse, the problem usually lies in some kind of not-so-simple routine where it could be one of a dozen different lines, and you find yourself having to wirte to a log everyother line... bleh...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: is there any way to record program flow for error checking later?

    Somewhat off-topic and of no tangible use here, but ,,,

    Anybody remember dBASE-IV .. from Ashton-Tate.
    It had a built-in TRACE feature, which I used from time to time.
    Pretty cool, but the output could be humongus.

    Seems like the basic suggestion posted so far is the best.. create a log
    (ie, a text file). It would seem that it would not entail thousands of lines
    of code if OP is satisfied with drilling-down to the specific issue.

    Spoo

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,680

    Re: is there any way to record program flow for error checking later?

    "dBASE-IV .. from Ashton-Tate." --- jeezes... you're showing your age there.... I used it for a while back when teaching myself databases...
    TRON was another useful command in BASIC ... similar function... not only was the output potentially huge but mucked up your display if you're using the screen for any meaningful interaction with the user.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,022

    Re: is there any way to record program flow for error checking later?

    Quote Originally Posted by jmsrickland View Post
    I don't think stack trace applies to VB. I'v heard of it in Java and C. I'm not even sure how it works in those languages but I suspect it has to do with debugging at an assembly like or low level but not sure.
    In VB6, there is the Call Stack which we call use to trace the stack and it comes in handy when debugging code although it is not available for us to log it at runtime.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width