Results 1 to 7 of 7

Thread: Silly debugging question

  1. #1

    Thread Starter
    Addicted Member New2VB's Avatar
    Join Date
    Jun 2000
    Location
    Los Angeles
    Posts
    161
    Is there any reason any one can think of why a program would generate a different response when it is run straight (i.e., run without break points) as opposed to when it is stepped through.

    I think that I have that situation right now. I don't believe that I am doing anything differently, but when I execute it straight through, a cursor in a masked text box invariably goes backwards 3 spaces, whereas when I step through it, it executes correctly and moves to the next space.

    I'd love any ideas.

  2. #2
    Guest
    the only thing I can think of is that when you debug and hit a breakpoint the program stops running. However, if you just run straight through it you program simply progresses. It seems like you might have an event that is occuring that is causing your program to do more than you want. Look into using DoEvents to see if it helps.

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    Generally adding breakpoints and stepping through your code shouldn't effect program operation, in a case like this however, because you are taking to focus away from the form and then replacing it, possibly the cursor is being manipulated?

    Just a thought

    Regards
    Regards

    Matt Brown
    Hamilton, NZ
    VB6 C++ in Visual Studio 6sp4
    VB.net Beta 1

  4. #4

    Thread Starter
    Addicted Member New2VB's Avatar
    Join Date
    Jun 2000
    Location
    Los Angeles
    Posts
    161
    Okay, I appreciate the above input, but, unfortunately, I am still getting different results depending on whether I execute the program straight through or step through after setting a break point. I have peared down the control and the code to the following snippet used in conjunction with a form on which there is a single Masked Edit Box named "MaskEdBox1".

    Here is the code

    Code:
    Private Sub MaskEdBox1_GotFocus()
        MaskEdBox1.Mask = "99 Minutes \and 99 Seconds."
                          '01234567890 123456
        Dim Minutes As Long
        Dim Seconds As Long
        Dim Time As Long
        
        Minutes = 0
        Seconds = 0
        
        Time = 360 ' Ordinarily I would get value from
                   ' a class designed to hold durations.
        
        ' Calculate Minutes and Seconds from raw Time    
        If Time > 3600 Then
            Time = 3600
        End If
        
        If Time > 3600 Then
            Time = 3600
        End If
        
        Do While Time > 59
            Minutes = Minutes + 1
            Time = Time - 60
        Loop
        
        Seconds = Time
        
        ' Format the Minutes and Seconds for Display
        If Minutes > 0 Then
            If Minutes > 9 Then
                MaskEdBox1.SelStart = 0
                MaskEdBox1.SelLength = 2
                MaskEdBox1.SelText = CStr(Minutes)
            Else
                MaskEdBox1.SelStart = 1
                MaskEdBox1.SelLength = 1
                MaskEdBox1.SelText = CStr(Minutes)
            End If
        Else
            MaskEdBox1.SelStart = 0
            MaskEdBox1.SelLength = 2
            MaskEdBox1.SelText = "00"
        End If
        
        If Seconds > 0 Then
            If Seconds > 9 Then
                MaskEdBox1.SelStart = 15
                MaskEdBox1.SelLength = 2
                MaskEdBox1.SelText = CStr(Seconds)
            Else
                MaskEdBox1.SelStart = 16
                MaskEdBox1.SelLength = 1
                MaskEdBox1.SelText = CStr(Seconds)
            End If
        Else
            MaskEdBox1.SelStart = 15
            MaskEdBox1.SelLength = 2
            MaskEdBox1.SelText = "00"
        End If
        MaskEdBox1.SelStart = 0
        MaskEdBox1.SelLength = 1
    End Sub
    
    Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)
        Dim TempLong As Long
        TempLong = 0
    
        ' If user presses spacebar move cursor to next valid
        ' data entry point and if user is in first column when
        ' the spacebar is pressed adjust the data in the digit 
        ' columns accordingly (I know that the code is written 
        ' will not format correctly if there is already old 
        ' data in the field)      
        Select Case KeyAscii
            Case 32
                Select Case MaskEdBox1.SelStart
                    Case 0
                        MaskEdBox1.SelStart = 15
                        MaskEdBox1.SelLength = 1
                    Case 1
                        MaskEdBox1.SelStart = 0
                        MaskEdBox1.SelLength = 1
                        TempLong = MaskEdBox1.SelText
                        MaskEdBox1.SelText = "0"
                        MaskEdBox1.SelStart = 1
                        MaskEdBox1.SelLength = 1
                        MaskEdBox1.SelText = TempLong
                        TempLong = 0
                        MaskEdBox1.SelStart = 15
                        MaskEdBox1.SelLength = 1
                    Case 15
                        MaskEdBox1.SelStart = 0
                        MaskEdBox1.SelLength = 1
                    Case 16
                        MaskEdBox1.SelStart = 15
                        MaskEdBox1.SelLength = 1
                        TempLong = MaskEdBox1.SelText
                        MaskEdBox1.SelText = "0"
                        MaskEdBox1.SelStart = 16
                        MaskEdBox1.SelLength = 1
                        MaskEdBox1.SelText = TempLong
                        TempLong = 0
                        MaskEdBox1.SelStart = 0
                        MaskEdBox1.SelLength = 1
                    Case Else
                        If MaskEdBox1.SelStart > 1 And MaskEdBox1.SelStart < 15 Then
                            MaskEdBox1.SelStart = 15
                            MaskEdBox1.SelLength = 1
                        Else
                            MaskEdBox1.SelStart = 0
                            MaskEdBox1.SelLength = 1
                        End If
                End Select
    
            ' If user inputs a valid numeric key write it to 
            ' to the control and move the cursor accordingly.
            Case Else
                MaskEdBox1.SelText = Chr(KeyAscii)
                Select Case MaskEdBox1.SelStart
                    Case 0
                        MaskEdBox1.SelStart = 1
                        MaskEdBox1.SelLength = 1
                    Case 1
                        MaskEdBox1.SelStart = 15
                        MaskEdBox1.SelLength = 1
                    Case 15
                        MaskEdBox1.SelStart = 16
                        MaskEdBox1.SelLength = 1
                    Case 16
                        MaskEdBox1.SelStart = 0
                        MaskEdBox1.SelLength = 1
                End Select
            End Select
        KeyAscii = 0
    End Sub
    If I set a breakpoint in the MaskEdBox1_KeyPress() subroutine any where before the Case Else statement intended to handle numeric input, and step through, the code executes correctly; otherwise, I get strange results.

    I appreciate anyone's input. Thanks.

  5. #5
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    I don't have time to go through all the code and look at it for you,

    However i still think that it is probably being caused by the focus changing when you swap into debug mode

    If you need to debug could I suggest that you use a series of debug.print statements around your code, I have used this sucessfully in the past where I want to examine what a function has done after it has executed.

    The data will be printed in the immediate window.
    Regards

    Matt Brown
    Hamilton, NZ
    VB6 C++ in Visual Studio 6sp4
    VB.net Beta 1

  6. #6
    Guest

    Unhappy Have had something similar

    In my case the project worked perfectly when stepped through but when run crashed out with locking errors.


    To do with opening and closing multiple Excel files. When stepping through Excel had the time to close down, when run was getting confused with multiple open sessions.

    I caren't see the same problem occuring with your code, try out Debug.Print and see if that makes a difference, or call the sleep api to put the prog to sleep for a few nano seconds between operations and see if that makes a difference????

  7. #7
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    I had problems (and still have) understanding VB's asyncronus behavior. You have to remember that even if you have step over a line in VB it still can be working on it. Take the shell command as a simple example. If you have this in your VB vode "Shell word" you will be continuing down to next line before word have finished starting.

    The focus shifting can also be a problem. I just now had a bad placed breakpoint so that I instead of debuging my apps right click popup menu I received the right click popup menu in the VB code instead.

    I don't relay understand the goal with your MaskEdBox1_KeyPress coding. Why can't you use the default behavior of it.

    I also have another suggestion.

    Replace

    Do While Time > 59
    Minutes = Minutes + 1
    Time = Time - 60
    Loop

    Seconds = Time

    with

    Minutes = Time \ 60
    Seconds = Time Mod 60

    Geting the whole number and the fraction part.
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

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