-
Hey guys.
Can you all help me out on this one?
I have a program that copies the contents of a file to another file but rearranges them (to mimic tables in a database). The more items there are in the original file, (obviously) the longer this takes.
So, I decided to time the event. I wanted the timer to be on the form at runtime. So, I added the timer to the form with a text box. When the command button to start this procedure, the first line is Timer2.Enabled = True.
The timer's routine is only to add one to the integer every second and then display the value in the text box.
So simple, right? Well, it doesn't work. The integer's Dim statement is in the General Declarations. And to be certain, I removed all functions from the original procedure except the timer event and, naturally, it works.
SO, the problem is, once the program starts copying the file information, it stops running the timer, and I don't know how to fix this.
I originally supposed some kind of DoEvents commmand, but I still haven't figured out what should be a pretty simple fix.
Any ideas?
Thanks.
-
Try declarling it as Static.
Code:
Private Sub Timer1_Timer()
Static iCount As Integer
iCount = iCount + 1
End Sub
Also, using GetTickCount might be a better approach to timing (as opposed to using a Timer).
Code:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
StartTime = GetTickCount
'Do your copying code here
StopTime = GetTickCount
MsgBox ("It took " & StopTime - StartTime & "ms to copy the file")
End Sub
-
Thanks for a speedy reply.
The Static command made no difference to the code. I suppose because the whole timer event is being ignored.
Your second method works quite well. I just wonder if there is a way to show a running timer of this event.
Overall, it is about 15 minutes (creating 5 rearranged files from the original).
-
Did you remember to set the Interval for the Timer? Remember, it will not work if it's set to 0.
-
Hi.
yes the interval was set to 1000 at design time.
Once I inserted a DoEvents command and tried to rewrite this as a series of loops but the closest I ever got was when it changed from 0 to 1 once.