CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Posts
    1

    Prog. Wont work w/o Debug statement>?! Timing Error?!?! Please help!

    When i take out a debug statement the program ceases to work. But it works flawlessly with the statement inside (and the debug window open. If you close the debug window it will fail again). Its not erroring out, just reading funky data from the comm port. HELP!
    Please email me if you find anything!!

    jeff gladnick
    [email protected]
    ------------------------------------------

    Private Sub MSComm1_OnComm()
    Static Jcount As Integer 'Controls how many lines of input we will read
    Dim JCurrentRow As String 'Accumulated string that is entered into test.txt
    Dim CheckPoint As Boolean 'Conditional Logic for Inner Do Loop
    Dim BufferChar As String 'Current Character in the MSComm1.input RCX buffer
    Dim TempFileString As String 'Temporary String to store file data in before database
    Dim i As Integer



    Select Case MSComm1.CommEvent 'If data is being recieved from
    Case comEvReceive 'the COMM port .....

    Do While MSComm1.InBufferCount <> 0 And MSComm1.PortOpen = True ' Outer loop.




    BufferChar = MSComm1.Input 'Set equal to char in Buffer
    'Debug.Print MSComm1.InBufferCount
    ' Debug.Print BufferChar; <------- Here is the problem statement

    If BufferChar = Chr(13) Then 'If data from serial port is a ...
    CurrentRowDisplay.Text = JCurrentRow 'Display Current Row to form textbox
    Open "test.txt" For Append As #1 'After a is encountered, Open
    Print #1, JCurrentRow 'The test.txt file and write then line
    ' Debug.Print ">"; JCurrentRow
    Close #1 'to it. Then close the file


    Jcount = 1 + Jcount 'increment counter
    CurrentlyAt.Text = Jcount 'Display to user the value of counter
    Debug.Print "Index:"; Jcount 'Debug stuff
    End If

    JCurrentRow = JCurrentRow + BufferChar 'Add character in buffer to string

    If Jcount = NumOfLines Then 'If the counter has reached its limit
    ' MSComm1.PortOpen = False
    ' Text1.Text = "Done!"

    Open "test.txt" For Input As #2 'Open Test.txt file and then
    Do While Not EOF(2) ' Loop until end of file.
    Line Input #2, TempFileString ' Read line into variable.


    Open "BigData.txt" For Append As #3 'Open big database for input
    Print #3, TempFileString 'Append the temporary data to larger database
    Close #3 'Close the file
    TempFileString = "" 'Clear the tempfile string
    Debug.Print TextLine ' Print to Debug window.

    Loop

    Close #2 ' Close file.

    Open "test.txt" For Output As #4 'Open Test.txt file and then
    ' Write #4, 'Remove all contents of temp file
    Close #4 'Close test.txt

    'TempFileString = LOF(2) 'Store it in a temporary string

    Jcount = 0 'Reset Jcount so it may start over
    Exit Do
    End If


    Loop
    End Select
    End Sub


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Prog. Wont work w/o Debug statement>?! Timing Error?!?! Please help!

    Try replacing the debug statement with a DoEvents.


  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Prog. Wont work w/o Debug statement>?! Timing Error?!?! Please help!

    I disagree - using a DoEvents command in an event subroutine can lead to a stack overflow, as the DoEvents command wont return until all events are handled - what if that includes another Comm port event?



    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured