By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,139 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,139 IT Pros & Developers. It's quick & easy.

Using Timer to Reduce Flicker

100+
P: 675
I am comparing picture names in a Folder with the names in a table, in order to find files that are not referenced within the database. I call these "Orphans"

This routine is imbedded in a large program, and I am only presenting a small fraction of the code. All variables are declared. Those beginning with str... are String, beginning with ii... are Long, lbl... are Labels, etc.

The routine worked, but the image flickered because line 22 of the code is executed ~80K times. To reduce the flicker, I inserted the lines marked as "Added line". The code still works, but the label on the form (lblDisplay) isn't displayed until cmdFindOrphans_Click exits. As a matter of fact, the timer event appears not to be triggered, as the function (code lines 28-30) is never executed.

A toggle breakpoint at line 25 has TimerInterval = 250, as it should. Before you ask, yes, the property sheet for the form has [Event Procedure], and the [. . .] gets me to the code corresponding to line 28.

Is there something I am missing here?


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     . . . . 
  3.     Me.TimerInterval = 0 'Added line
  4. End Sub 
  5.  
  6. cmdFindOrphans_Click
  7.     iiRecCt = 0
  8.     iiOrphanCt = 0
  9.     lblDisplay.Caption = ""
  10.     Set dbs = CurrentDb
  11.     Set rst = dbs.OpenRecordset("SELECT . . .")
  12.  
  13.     strFile = Dir(strPath & "\*.*")
  14.     Me.TimerInterval = 250 'Added line
  15.     Do Until strFile = ""
  16.         iiRecCt = iiRecCt + 1
  17.         If IsOrphan(arg1, . . .) = True Then
  18.             iiOrphanCt = iiOrphanCt + 1
  19.             . . . .
  20.         End If
  21.         lblDisplay.Caption = "Checked=" & iiRecCt & "   Orphans=" & iiOrphanCt
  22.         'Me.Repaint 'Original line
  23.         strFile = Dir()
  24.     Loop
  25.     Me.TimerInterval = 0 'Added line
  26. End Sub
  27.  
  28. Private Sub Form_Timer() 'Added line
  29.     Me.Repaint 'Added line
  30. End Sub 'Added line
  31.  
OldBirdman
Jan 12 '08 #1
Share this Question
Share on Google+
6 Replies


missinglinq
Expert 2.5K+
P: 3,532
I've frequently seen the use of the Timer given as the cause of screen flicker, but I've never heard of it being used to suppress screen flicker! The problem here, I expect, for the label not appearing, is that you're repainting the screen too frequently. Timer Interval = 1000/second, so an Interval of 250 means the screens repainting every 1/4 of a second.

Linq ;0)>
Jan 12 '08 #2

100+
P: 675
I could have no label, and no counters. The problem would go away. I would have to substitute the 'hourglass' for the cursor, to show I was actually doing something, and not just looping or idle.

I had flicker when I did not have the timer. I checked 4,000 files in about 9 seconds, so the repaint rate would have been about 400/second, somewhat faster than 4/second.

I could live with the flicker, but I felt that the repaint might be quite expensive, and reducing the number of times by a factor of 100 might speed it up.

OldBirdman
Jan 13 '08 #3

FishVal
Expert 2.5K+
P: 2,653
Hi, OldBirdman.

To the best of my knowledge events (including that from form timer) are not asynchronous in VBA. No timer event will be fired while code is running.
You may try to use win timer but this maybe a bit unsafe.

Regards,
Fish
Jan 13 '08 #4

ADezii
Expert 5K+
P: 8,623
Hi, OldBirdman.

To the best of my knowledge events (including that from form timer) are not asynchronous in VBA. No timer event will be fired while code is running.
You may try to use win timer but this maybe a bit unsafe.

Regards,
Fish
I do believe that FishVal is right on this one, as long as code execution is contained within the Do...Loop, the Timer() Event will never fire.
Jan 13 '08 #5

100+
P: 675
Thank you! Not sure what "asynchronous" is, but that's OK.

Within my loop, I inserted an iiCounter and incremented for each iteration of the loop. Then:
Expand|Select|Wrap|Line Numbers
  1. . . . 
  2. If iiCounter mod 1000 = 0 then 
  3.     lblStatus.Caption = "Checked=" & iiCounter & " --- Found=" & iiFound 'Checked=3000 --- Found=8'
  4.     Me.Repaint 
  5. End If
  6. . . . 
  7.  
I can adjust the speed of the display update by tinkering with the 'mod' value. I consider this problem solved. Thank you all again.

OldBirdman
Jan 15 '08 #6

FishVal
Expert 2.5K+
P: 2,653
Not a problem.
Good luck.
Jan 15 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.