Results 1 to 4 of 4

Thread: progress for sequential file

  1. #1

    Thread Starter
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290

    progress for sequential file

    ok i almost have this working however i'd like to make it more efficient. right now i read in a file with the input function and use the loc and LOF functions to determine the length and position of the record. in doing so i use a progress bar. however this is very slow and i would like to make it run faster. i know i could make the number greater in the input function but i never know how long a record is to the carriage return and line feed ASCII codes. what i would like to do is use the input statement rather then the function if possible and read each column into a variable. I know how many columns there are just not the length. here is the code so far.


    VB Code:
    1. Dim sBuffer As String
    2.     Dim x As String
    3.    
    4.     With Me.ProgressBar1
    5.         .Min = 0
    6.         .Max = FileLen(App.Path & "\ClassPosition_SkillList.txt")
    7.     End With
    8.    
    9.     Open App.Path & "\ClassPosition_SkillList.txt" For Binary As #1   ' Open file just created.
    10.    
    11.     Do While Loc(1) < LOF(1)   ' Loop until end of file.
    12.         DoEvents
    13.         x = Input(1, #1)
    14.        
    15.         If x <> "" Then
    16.             If Asc(x) <> 10 And Asc(x) <> 13 Then
    17.                 sBuffer = sBuffer & x
    18.             Else
    19.                 sBuffer = ""
    20.             End If
    21.         End If
    22.         Me.ProgressBar1.Value = Loc(1)
    23.     Loop
    24.     Close #1

    any help will be greatly appreciated.

  2. #2
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    How large will "ClassPosition_SkillList.txt" get to be? If its reasonable small (< 2 MB), I'd suggest, you read the whole thing into a string and then split that by vbCRLF. You would then have each line in an array's element and also will immesely speed up the process.

    HTH

    Regards

    KayJay

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  3. #3

    Thread Starter
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    thanks KayJay and anyone else that may have been thinking about this but i figured out a way to get it to work by using the line input statement. here is my code and it's much faster


    VB Code:
    1. Dim sBuffer As String
    2.     Dim x As Long
    3.    
    4.     With Me.ProgressBar1
    5.         .Min = 0
    6.         .Max = FileLen(App.Path & "\ClassPosition_SkillList.txt")
    7.     End With
    8.    
    9.     Open App.Path & "\ClassPosition_SkillList.txt" For Input As #1   ' Open file just created.
    10.    
    11.     Do While Not EOF(1)   ' Loop until end of file.
    12.         DoEvents
    13.         Line Input #1, sBuffer
    14.         x = Len(sBuffer) + 2 'add two to vbCrLf
    15.         Debug.Print sBuffer
    16.         With Me.ProgressBar1
    17.             .Value = .Value + x
    18.         End With
    19.     Loop
    20.     Close #1   '

  4. #4
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    It is far more faster to read into memory the whole text file than hitting the disk every so often. Memory access is faster that file i/o.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

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