|
-
Jan 24th, 2004, 08:42 AM
#1
Thread Starter
Registered User
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:
Dim sBuffer As String
Dim x As String
With Me.ProgressBar1
.Min = 0
.Max = FileLen(App.Path & "\ClassPosition_SkillList.txt")
End With
Open App.Path & "\ClassPosition_SkillList.txt" For Binary As #1 ' Open file just created.
Do While Loc(1) < LOF(1) ' Loop until end of file.
DoEvents
x = Input(1, #1)
If x <> "" Then
If Asc(x) <> 10 And Asc(x) <> 13 Then
sBuffer = sBuffer & x
Else
sBuffer = ""
End If
End If
Me.ProgressBar1.Value = Loc(1)
Loop
Close #1
any help will be greatly appreciated.
-
Jan 24th, 2004, 09:04 AM
#2
Frenzied Member
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
-
Jan 24th, 2004, 09:10 AM
#3
Thread Starter
Registered User
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:
Dim sBuffer As String
Dim x As Long
With Me.ProgressBar1
.Min = 0
.Max = FileLen(App.Path & "\ClassPosition_SkillList.txt")
End With
Open App.Path & "\ClassPosition_SkillList.txt" For Input As #1 ' Open file just created.
Do While Not EOF(1) ' Loop until end of file.
DoEvents
Line Input #1, sBuffer
x = Len(sBuffer) + 2 'add two to vbCrLf
Debug.Print sBuffer
With Me.ProgressBar1
.Value = .Value + x
End With
Loop
Close #1 '
-
Jan 24th, 2004, 09:12 AM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|