MegaByte File-Counter please help !

supercar
supercar used Ask the Experts™
on
Hello :)

i have a modul, that is converting many files in different subdirectory's. A kind of DOC-2-TXT Converter.

Do
' --------- Entry Point for the Converter Call --------
filesize=Convert_My_Document(d_Path & d_File) ' Convert Document
Label1.Caption = "Speed: " & MB_per_Sec & " MB/sec."
DoEvents
' --------- All converting stuff is ready now ---------
Loop While (all files done)

And now (because it's very much to convert) i want to add a "Progress indicator" but not with 50 percent ready or something, no i want a " xxx MB/sec " Display in "realtime" that means during the converting progress.

I have the Filesize of each file and i think i can use GetTickCount for this, but i have no idea how to make a "serios" counter with this.

In fact means this: Process one File, Take the Time of this and display the average MB/sec of all files so far.

Thanks for helping in advance and sorry for my english :)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:

dim MBPerSec as long
dim totalTime as long
dim nRead as long

totalTime = 0
MBPerSec = 0
nRead = 0

...

nRead = 'what you have converted so far in bytes
totalTime = totalTime + GetTickCount 'in milliseconds
MBPerSec = CDbl(nRead) / totalTime

you could use double or float if you want fractions of megabytes/s.

Commented:
You can also use the "real time" in your application


Dim nTimer as double

'...
ntimer=timer() '=seconds since midnight...

'...dostuff

mpPerSec = CDbl(nread)/(timer-ntimer)/2^20 'Divide by a real megabye

Author

Commented:
nRead = 'what you have converted so far in bytes
totalTime = totalTime + GetTickCount 'in milliseconds
MBPerSec = CDbl(nRead) / totalTime


Hm... must i divide by 1000 for seconds ?

if i have a label must i display it with

.caption = Format$((MBPerSec), "###,##") '& " mb" ???

How do i add this that it looks like "34,12 MB/sec" ?

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
And what var type (for the bytes counter) must i use ?
If i make lets say 40 GigaByte - would a long be enough ?

Author

Commented:
totalTime = totalTime + GetTickCount 'in milliseconds

...gives a buffer overflow

Commented:
change it a little

GetTickCount gives ticks from beginning of the system start so you should subtract from some startpoint and add incrementally.

a long is a 32 bits entity although VB uses the highest bit to indicate negative numbers. Now that means you have 31 bits to work with in positive range. That is roughly 2 Giga. What you can do is to only save in kbytes and not bytes. That would give you a counter available to hold 2 000 Gigabytes or 2 Terabytes.

dim MBPerSec as long
dim totalTime as long
dim nRead as long
dim tickStart as long

totalTime = 0
MBPerSec = 0
nRead = 0

...

tickStart = GetTickCount

'your loop

nRead = 'what you have converted so far in kbytes
totalTime = totalTime + (GetTickCount - tickstart) 'in milliseconds

MBPerSec = nRead / totalTime




Commented:
you could also use double to get hold of the fractions. Maybe that is what you want:

dim MBPerSec as double
dim totalTime as double
dim nRead as double
dim tickStart as long

nRead = 0#
totalTime = 0#
tickStart = GetTickCount

'you loop starts here

nRead = nRead + CDbl(what you have converted in bytes) / 1000.0

totalTime = totalTime + CDbl(GetTickCount - tickStart)

MBPerSec = nRead / totalTime


Author

Commented:
totalTime = totalTime + GetTickCount 'in milliseconds

...gives a buffer overflow

Commented:
I gave you the solution. Please try it.

Author

Commented:
totalTime = totalTime + GetTickCount 'in milliseconds

...gives a buffer overflow

Author

Commented:
ok i try it now

Author

Commented:
Private TotalTime As Double
Private TickStart As Long
Private MBPerSec As Double
Private ConvertedBytes As Double

' *** Startup ***
TickStart = GetTickCount
TotalTime = 0#
ConvertedBytes = 0#

' *** My Loop ***

' processing my file here -> call xyz <-
ConvertedBytes = ConvertedBytes + CDbl(WFD.nFileSizeHigh * 65536 + WFD.nFileSizeLow) / 1000#

TotalTime = TotalTime + CDbl(GetTickCount - TickStart)
MBPerSec = ConvertedBytes / TotalTime
Form1.labelSpeed = Format$((MBPerSec), "###0.00") & " MB/sec"

' *** Repeat until not more files

WFD is WIN32_FIND_DATA and WFD.nFileSizeLow shows the correct file size in bytes for each file.

But your code shows weird results - like "0.01 MB/sec" - this is WRONG - it should be around 2 MB. it did work with bytes before until it crashed because of a to big number for bytes. but now it shows 0.01 this is not the correct value or did i miss something ?



Commented:
I guess I have to test my code.. wait

Commented:
TotalTime = TotalTime + CDbl(GetTickCount - TickStart)

should be

TotalTime = TotalTime + CDbl(GetTickCount - TickStart)/1000.0

forgot to convert it to seconds.. GetTickCount returns millseconds.

Sorry about that

Author

Commented:
i will not bother you but it shows now 1789657,23 or something....

Commented:
Divide that by 2^20 to get MB/S

Commented:
Also what was wrong with

mbPerSec = CDbl(nread)/(timer-ntimer)/2^20

?

Author

Commented:
it does not work because i have to count KB and not bytes.

Author

Commented:
Private TickStart As Double
Private MBPerSec As Double
Private ScannedBytes As Double

TickStart = Timer

***LOOPSTART***

conBytes = conBytes + CDbl(WFD.nFileSizeHigh * 65536 + WFD.nFileSizeLow) / 1024#
               
MBPerSec = CDbl(conBytes) / (Timer - TickStart) / 2 ^ 20
               
Form1.labelSpeed = Format$((MBPerSec), "###0.00") & " MB/sec"
***LOOPEND***

Well, it starts with 1785483475 MB/s and goes rapidly down to, 0.01 MB/s and stays there - NOT CORRECT !


Commented:
well change

mbPerSec = CDbl(nread)/(timer-ntimer)/2^20

to

kbPerSec = CDbl(nread)/(timer-ntimer)/2^10

If you just "add up" the filesizes you are counting BYTES...

You need to scale them to the correct dimension of course...

2^10 Bytes = 1024 Byte = 1 KByte
2^20 Bytes = 1024 KByte = 1 Megabyte

And please use the CORRECT conversion factor of 1024 for byte -> KByte ... I hate HD-Manufracturer for using this "cheap approimation"

;)


Commented:
picky guys..

since you are counting in kbytes, you would have to change

MBPerSec  to MBPerSec = Kbytes/seconds / 1000

and if you really wanna have kbyte then divide your bytes with 1024

I am giving you guidelines not precise code. I've heard that we should encourage the questioner find out some details of his/her own. Please don't get offended, I am merely passing some info. :)

Author

Commented:
Ok finally this works :) 100 pts

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial