Results 1 to 5 of 5

Thread: Is there a quicker method

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    London Occupation: Desktop Developer
    Posts
    141

    Question Is there a quicker method

    Hi was wondering if anyone could look over the following process and give any suggestions for speeding it up, using VBA in Access 97, I am open a file reading it line by line, for each line that is read I am formating the data and writing to a new file. The process takes about 20 minutes (100/150MB file)

    VB Code:
    1. Open "C:\PostPay\file" & strType & lngProcessID & ".txt" For Input As #1
    2. Open "C:\PostPay\fileResult" & strType & lngProcessID & ".txt" For Output As #2
    3.  
    4.  
    5. Do Until EOF(1)
    6.   Line Input #1, strFile
    7.  
    8.   'Ignore the header
    9.   If Not (InStr(1, strFile, "|") > 0) Then
    10.  
    11.     vntArray = Split(strFile, ",")
    12.    
    13.     For intCount = 0 To 16
    14.       'Edit the File
    15.  
    16.       If intCount = 0 Then
    17.      
    18.         Select Case Mid$((vntArray(intCount)), 2, 3)
    19.        
    20.           Case "GRA"
    21.             'Grand Total - MUST ALWAYS INCLUDE OR ABORT PROCCESS
    22.             strFile = Trim$(Mid$(vntArray(intCount), 2, 11))
    23.             blnGrandTotal = True
    24.            
    25.           Case "EH_"
    26.             'Guiding only
    27.             strFile = Trim$(Mid$(vntArray(intCount), 2, 9))
    28.           Case Else
    29.             'Exclude spaces and ".rcd"
    30.            
    31.             strFile = Trim$(Mid$(vntArray(intCount), 2, InStr(1, vntArray(intCount), ".rcd") - 2))
    32.       End Select
    33.      
    34.       Else
    35.         strFile = strFile & "," & Trim$(vntArray(intCount))
    36.       End If
    37.     Next
    38.    
    39.     Print #2, strFile & "," & dtmDate & "," & lngProcessID
    40.    
    41.   End If
    42. Loop
    43.  
    44. Close #1
    45. Close #2

    Any help much appreciated
    Last edited by Richyrich; Feb 28th, 2002 at 04:58 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    London Occupation: Desktop Developer
    Posts
    141

    Question

    I am presuming that I have followed the most efficient way for doing this?

  3. #3
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    there are a couple of things i can see that would speed up "processing" very slightly, but won't make much different overall. the time it takes is really just because of the fact that you are going through a 150Mb file line by line.

    can't really do much about that.

    20mins doesn't sound so bad to me, considering anyway
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    London Occupation: Desktop Developer
    Posts
    141
    what are the couple of things?

  5. #5
    Si_the_geek
    Guest

    Re: Is there a quicker method

    your "if" statements could be re-arranged a bit, not sure how much time it'll save tho..

    VB Code:
    1. Open "C:\PostPay\file" & strType & lngProcessID & ".txt" For Input As #1
    2. Open "C:\PostPay\fileResult" & strType & lngProcessID & ".txt" For Output As #2
    3.  
    4. strFile = "|"    'assuming the header bit doesn't repeat!
    5. Do Until EOF(1) Or InStr(1, strFile, "|") = 0
    6.   Line Input #1, strFile
    7. Loop
    8.  
    9. Do Until EOF(1)
    10.   Line Input #1, strFile
    11.  
    12.     vntArray = Split(strFile, ",")
    13.    
    14.  
    15.         Select Case Mid$((vntArray(0)), 2, 3)
    16.        
    17.           Case "GRA"
    18.             'Grand Total - MUST ALWAYS INCLUDE OR ABORT PROCCESS
    19.             strFile = Trim$(Mid$(vntArray(0), 2, 11))
    20.             blnGrandTotal = True
    21.            
    22.           Case "EH_"
    23.             'Guiding only
    24.             strFile = Trim$(Mid$(vntArray(0), 2, 9))
    25.           Case Else
    26.             'Exclude spaces and ".rcd"
    27.            
    28.             strFile = Trim$(Mid$(vntArray(0), 2, InStr(1, vntArray(0), ".rcd") - 2))
    29.       End Select
    30.  
    31.     For intCount = 1 To 16
    32.       'Edit the File
    33.  
    34.         strFile = strFile & "," & Trim$(vntArray(intCount))
    35.     Next
    36.    
    37.     Print #2, strFile & "," & dtmDate & "," & lngProcessID
    38.    
    39. Loop
    40.  
    41. Close #1
    42. Close #2

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