Results 1 to 3 of 3

Thread: Speeding up this code.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    41

    Speeding up this code.

    Code:
    Private Sub AuthData_DataArrival(ByVal bytesTotal As Long)
    
        On Error Resume Next 'If we run into an error continue
        
        Dim Lens As Long, tmpLng As Long, AData As String 'Declare stuff
        
        Lens = bytesTotal 'Grab how many bytes there are
        
        Do While Lens >= 6 'Do the following as long as the len is over 6 bytes.
            
            AuthData.PeekData AData$, vbString, Lens 'Get the data without removing it from the buffer
            tmpLng = GetWord(Mid$(AData$, 5, 2)) + 6 'Get length of packet
        
            If Lens >= tmpLng Then  'If the whole packet is in the data
                
                AuthData.GetData AData$, vbString, tmpLng 'Get the data and remove packet from buffer
                Call Parse(AData$)  'Process the packet
                Lens = Lens - tmpLng
            
            Else
                
                Exit Sub
            
            End If
    
        Loop
    
    End Sub
    Is there anyway to speed this code up or make it faster? Also how else can I make VB code more faster, and less memory intesnse?
    Last edited by gthkane; Dec 16th, 2008 at 05:49 PM.

  2. #2
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Speeding up this code.

    This is quite seems like the fastest code. The things, that is may causing any slow down are in your own methods, just like Parse(), GetWord().

  3. #3
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Speeding up this code.

    This won't help your speed, but you're using 'On Error Resume Next' without 'closing' it.

    That can cause you problems.
    For instance, if a error happens in your Parse procedure, the code will jump to back to the calling sub, or even somewhere else.

    That can can give some odd errors and tricky debugging.

    You want to make sure to use 'On Error Goto 0' to 'close' the error avoidance.

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