Some wild calculations to get a pourcentage
This is a file that I compressed with my own algorithm (omacmodi.cpr) and need to read back (like a zip or something). Every line have a different lengh and I need to know how many entries are in there so I can display the pourcentage on a progress bar.
Not only I can't find a better way to do this but I find that the calculation for "FloodPercent" is a little bit suspicious...
It works, but is there a better way?
VB Code:
Open App.Path & "\omacmodi.cpr" For Input As #1
' Count the number of records (or entries).
While Not EOF(1)
Input #1, A$: NB = NB + 1
Wend
Seek #1, 1 ' Back to beginning of file
While Not EOF(1)
Input #1, A$: Rec = Rec + 1
If 100 - Int(((100 / NB * (NB - Rec)))) <> LastRec Then
Frm_Modi.Pnl_Status.FloodPercent = 100 - Int(((100 / NB * (NB - Rec))))
End If
LastRec = 100 - Int(((100 / NB * (NB - Rec))))
' If I don't do this, the form is not refreshed. That's another thing!
openforms = DoEvents
If Len(A$) <> 3 Then
MODE$ = Left$(A$, 3)
For I = 4 To Len(A$) - 5 Step 5
code$ = Mid$(A$, I + 1, 5)
TB_OM.AddNew
TB_OM("Code") = code$
TB_OM("Mode") = MODE$
TB_OM.Update
Next
End If
Wend
It took me about a day to build this like 5 years ago. It's the pourcentage that was a *****!
Can anyone make this better or is it just a piece of art like it is? (ya)
Thank you.
PS: There's only 5 hits for "Some wild calculations" on Google
Re: Some wild calculations to get a pourcentage
Well hello there!
After all those years I needed that calculation again and I think that it is time
to thank you for your help and the attention you took to answer me.
It works very well.
Thank you very much si_the_geek!
Re: Some wild calculations to get a pourcentage
No problem.. I'm surprised it's still useful to you after all this time! :D
Re: Some wild calculations to get a pourcentage
' For sequential files LOC returns position divided by 128
if (LOF(fh) \ 128)<>0 then Progress = LOC(fh) / (LOF(fh) \ 128)
Not sure if it should read / or \... you could try.