|
-
Feb 26th, 2004, 12:53 AM
#1
Thread Starter
Member
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
~~~~~~~~~~~~~~~~~~~~
There's always something 
~~~~~~~~~~~~~~~~~~~~ <Any link censored by moderator>
-
Feb 26th, 2004, 07:11 AM
#2
Here's a few improvements:
VB Code:
'declare your variables!
Dim iFileNo As Integer
Dim iFileLen As Long
Dim iLengthSoFar As Long
Dim A$
Dim I As Integer
Dim iCurrentPercent As Integer
Dim iLastPercent As Integer
Dim Rec
iFileNo = FreeFile 'Use FreeFile, not a specific number!
Open App.Path & "\omacmodi.cpr" For Input As #iFileNo
iFileLen = LOF(iFileNo) 'Get length of file
iLengthSoFar = 0 'Store amount read so far
While Not EOF(iFileNo)
Input #iFileNo, A$
iLengthSoFar = iLengthSoFar + Len(A$) + 1 'nb: +1 may not be right, it may be +2
'to get percentage use: min% + ((counter/max_count)*(max% - min%))
'assuming you want 0 to 100, that's: 0+(counter/max_count)*(100-0)
iCurrentPercent = (iLengthSoFar / iFileLen) * 100
If iLastPercent <> iCurrentPercent Then
Frm_Modi.Pnl_Status.FloodPercent = iCurrentPercent
End If
iLastPercent = iCurrentPercent
'openforms = 'no need for an assignment, DoEvents can be run on its own
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 I
End If
Wend
Close #iFileNo
-
Mar 2nd, 2007, 08:15 AM
#3
Thread Starter
Member
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!
~~~~~~~~~~~~~~~~~~~~
There's always something 
~~~~~~~~~~~~~~~~~~~~ <Any link censored by moderator>
-
Mar 2nd, 2007, 11:21 AM
#4
Re: Some wild calculations to get a pourcentage
No problem.. I'm surprised it's still useful to you after all this time!
-
Mar 7th, 2007, 01:22 PM
#5
New Member
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.
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
|