Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone plz look at this? 1

Status
Not open for further replies.

adi316

Programmer
Sep 10, 2002
35
0
0
CA
hi, this function gives an "overflow" error 6 at random times, and i have no idea why!! plz give me some ideas

Private Sub MSComm1_OnComm()

If FlStart = True Then 'Button "Start" pressed
If MSComm1.InBufferCount >= 1 Then 'Input buffer is not empty

Ch = MSComm1.Input 'Read from the input buffer
InLine = InLine + Ch

'Check if end of line(CR+Lf) presents in string
If InStr(InLine, (Chr(13)) + (Chr(10))) > 0 Or InStr(InLine, (Chr(10)) + (Chr(13))) > 0 Then

'Update temporary log file with new data.
Open TempSaveName For Append As #1 'Open file
Print #1, InLine;
Close #1 'Close file
'Clean window every 10K to avoid memory issues
If Len(txtRx) >= 10000 Then
txtRx.Text = ""
End If

txtRx.Text = txtRx.Text + InLine
txtRx.SelStart = Len(txtRx)

InLine = ""
End If
End If
End If

End Sub
 
Are you trying to concatenate two strings on this line?

txtRx.Text = txtRx.Text + InLine

If so use the ampersand.

txtRx.Text = txtRx.Text & InLine Thanks and Good Luck!

zemp
 
yes i am trying to add the current line i got from the port into the textbox (i am keeping a log of data from the parallel port) i will try that thanks (howver as i said the prog does work for maybe 24 hours before it unexpectedly get that error) so i am thinking maybe it is from a message it recieves from the port?
 
You can do a search on this forum for 'Overflow' and you will see many threads about this error. There may be one that helps you out. Thanks and Good Luck!

zemp
 
Code:
Private Sub MSComm1_OnComm()

    'SO Many issues here! _
        1.  Do NOT use the ordinal for the file open / print /close operations _
            See "FreeFile" and examples in Help _
        2.  Chr(10) + Chr(13) !! vbNewLine, so use that and omit the _
            (then REDUNDANT) check for the reversed string. _
        3.  As otherwise mentioned the "+" operator may be confusing as it _
            can denote either addition (math) or concatenation (string). _
            Replace it where you manipulate STRINGS of Text with the _
            ampersand ("&"). _
        4.  "InLine" is concatenated with the buffer content unless / _
            until a "NewLine" is detected.  When the "NewLine" is found, _
            "InLine" is somply appended to the output and THEN "InLine" is _
            Cleared (set to the zero length string.  However this is done _
            FOLLOWING the check / manipulation of the text box.  It would _
            be clearer to 'flush' "InLine" immediatly following the _
            Print / Close statements. _
        5.  The nesting of the logic could be simplified and improve both the _
            program flow and readability.
    '   6. The inclusion of the cleaning of the text box within the process _
            of re-writting the output seems quite un-necessary.  IF you _
            are goung to track the progreaa via reviewing some part of the _
            transfer and limit the 'tracking' mechanisim, it would seem _
            just as appropiate to do it independently of wheather the input _
            stream included the NewLine indicator.

    Dim FilHdl As Integer

    If (FlStart = False) Then               'Button "Start" NOT pressed
        Exit Sub
    End If

    If (MSComm1.InBufferCount < 1) Then    'Input buffer is empty
        Exit Sub
    End If

    Ch = MSComm1.Input                  'Read from the input buffer
    InLine = InLine + Ch
               
    'Check if end of line(CR+Lf) presents in string
    If (InStr(InLine, vbNewLine) = 0) Then
        Exit Sub
    End If

    txtRx.Text = txtRx.Text + InLine
    txtRx.SelStart = Len(txtRx)

    'Clean window every 10K to avoid memory issues
    If Len(txtRx) >= 10000 Then
      txtRx.Text = &quot;&quot;
    End If

    'Update temporary log file with new data.
    FilHdl = FreeFile
    Open TempSaveName For Append As #FilHdl
    Print #FilHdl, InLine;
    Close #FilHdl
    InLine = &quot;&quot;

End Sub

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
tut tut.... broke your own rule :)

txtRx.Text = txtRx.Text + InLine
txtRx.Text = txtRx.Text & InLine




 
ADoozer

Tis true, sadly sadly true. Alas alack and awry ... troubles seem to abound when just trying to chip in, perhaps i should just remain silent


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
gotta get myself some of those chunky smiley face things...

the old fashioned :) just doesnt cut it for humor these days....

michaelred: it was merely constructive criticism, keep up the good work..
 
MichaelRed thanks a lot for the post! i will test it out today.
 
How big is inline allowed to get?
What happens if you never get an end of line character?
 
lionelhill: well i am expecting a message which is more or less a fixed format. basically every minute i get a header msg and then around 30 lines of output. Each line had an end of line character (however sometimes it is CR + LF and sometimes LF + CR, which i can do nothing about, but i have to still recognise it as a new line)

im thinking the overflow can possibly be caused by an unexpected character being recieved?? hawever a string should handle all characters... i am confused!
 
MichaelRed -- i tried using ur code and still getting same problem. i'm lost [ponder]
 
try adding a SIMPLE error trap. in the err handler section just do &quot;STOP&quot;. when the err occurs, the procedure will just &quot;bomb&quot; on the STOP inst. Review the various variables in the procedure. one of the numeric ones should say overflow, or not be calculated. report the findings. perhaps this can help or at least illumnate the issue a bit.


are you SURE the problem is in THIS procedure?


you COULD get elaborate and have different err handlers for the various parts of the procedure. that would serve to localize the issue -at least if the error occurs within the procedure-


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top