469,091 Members | 1,147 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,091 developers. It's quick & easy.

Making label control flash

doma23
107 100+
Hi,
I have a label control lblLocked, and 5 comboboxes.
These comboboxes serve as a search functions by limiting values in each other based on user's selection.
On each combobox there is an After Update event set which checks if ListCount property on each of these combobxes equals to 1.
If the condition is true, than I want lblLocked which is by defualt invisible to flash 2-3 times and then stop, just making it visible.
How can I do this?

I've been searching on the internet and I've ran on TimeInterval property and On Timer event, and although I was trying something, I couldn't figure it out how they can help me, as the code on form's On Timer event code is being executed constantly, based on Time Interval property.

This is basically the algorithm that I need:

Expand|Select|Wrap|Line Numbers
  1. If Form_frmMain.cbo1.ListCount = 1 and Form_frmmain.cbo2.ListCount = 1 and.... Then
  2. HOLD NEXT LINE FOR ONE SECOND
  3. Form_frmMain.TimerInterval = 200
  4. AFTER ONE SECOND DO THIS
  5. Form_frmMain.TimerInterval = 0
  6. Form_frmMain.lblLocked.Visible = True
  7. End If
  8.  
Tnx!
Sep 16 '10 #1

✓ answered by Megalog

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public lngCount As Long
  5.  
  6. 'The AfterUpdate events from whatever control you 
  7. 'want this to activate on. Duplicate this for each 
  8. 'combo/list control
  9.  
  10. Private Sub cbo1_AfterUpdate()
  11.     Call CheckLists
  12. End Sub
  13.  
  14. Private Sub cbo2_AfterUpdate()
  15.     Call CheckLists
  16. End Sub
  17.  
  18.  
  19. Private Sub CheckLists()
  20. 'This checks the criteria (Listcounts) and 
  21. 'sets the timer off if it matches, otherwise 
  22. 'hides the possibly visible label.
  23.  
  24.     lngCount = 0
  25.     If Form_frmMain.cbo1.ListCount = 1 and Form_frmmain.cbo2.ListCount = 1 and.... Then
  26.         Me.TimerInterval = 250
  27.     Else
  28.         Me.lblLocked.Visible = False
  29.     End If
  30.  
  31. End Sub
  32.  
  33. Private Sub Form_Timer()
  34. 'Timer event itself.  Flashes on and off 6 times,
  35. 'then turns the interval off and leaves the label visible.
  36.  
  37.     If lngCount < 6 Then
  38.         Me.lblLocked.Visible = Not Me.lblLocked.Visible
  39.         lngCount = lngCount + 1
  40.     Else
  41.         Me.lblLocked.Visible = True
  42.         Me.TimerInterval = 0
  43.     End If
  44.  
  45. End Sub

7 4638
munkee
374 256MB
I am not too farmiliar with using timers etc so I usually just revert to creating loops. Not elegant but you will see how it runs.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command74_Click()
  2. Dim currenttime As Date
  3. currenttime = Now()
  4. Do
  5. Loop While Now() < currenttime + TimeSerial(0, 0, 5)
  6. MsgBox "5 seconds done"
  7. End Sub
  8.  
Sep 16 '10 #2
doma23
107 100+
Unfortunately, it doesn't help. I cannot get it to work.
I've put multiple do loop while statements, with 1 second timeserial, and with the vba statements "lblLocked.Visible=True" in one and then "lblLocked.Visible=True" in next.
Although it's not satisfying solution, I just wanted to test it, and it didn't work.
Sep 16 '10 #3
Megalog
378 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public lngCount As Long
  5.  
  6. 'The AfterUpdate events from whatever control you 
  7. 'want this to activate on. Duplicate this for each 
  8. 'combo/list control
  9.  
  10. Private Sub cbo1_AfterUpdate()
  11.     Call CheckLists
  12. End Sub
  13.  
  14. Private Sub cbo2_AfterUpdate()
  15.     Call CheckLists
  16. End Sub
  17.  
  18.  
  19. Private Sub CheckLists()
  20. 'This checks the criteria (Listcounts) and 
  21. 'sets the timer off if it matches, otherwise 
  22. 'hides the possibly visible label.
  23.  
  24.     lngCount = 0
  25.     If Form_frmMain.cbo1.ListCount = 1 and Form_frmmain.cbo2.ListCount = 1 and.... Then
  26.         Me.TimerInterval = 250
  27.     Else
  28.         Me.lblLocked.Visible = False
  29.     End If
  30.  
  31. End Sub
  32.  
  33. Private Sub Form_Timer()
  34. 'Timer event itself.  Flashes on and off 6 times,
  35. 'then turns the interval off and leaves the label visible.
  36.  
  37.     If lngCount < 6 Then
  38.         Me.lblLocked.Visible = Not Me.lblLocked.Visible
  39.         lngCount = lngCount + 1
  40.     Else
  41.         Me.lblLocked.Visible = True
  42.         Me.TimerInterval = 0
  43.     End If
  44.  
  45. End Sub
Sep 16 '10 #4
doma23
107 100+
@Megalog

Haha. It works a charm! Beautiful. Tnx!
I wasn't able to find the solution on internet for this at all. There were people asking the same question, but nobody provided even direction to the solution.
I believe the bytes forum might be the first. :)
I knew that there needs to be something with setting TimerInterval to zero, but didn't know how to make the logical sequence.
Even after I saw your code, it took me a bit to understand how it works. I was confused as there was no loop for counting, and then I realized that the loop is basically 250ms of Timer itself.

The only thing is that it doesn't flash 6 times, maybe only 3 times. I think it has to do something with this line:
me.lbllocked.visible = not me.lbllocked.visible

I don't fully understand it.
Sep 17 '10 #5
Megalog
378 Expert 256MB
The timer handles the frequency of the event. The lngCount value determines what happens in the event.

This line simply toggles the .Visible property by assigning it's opposite value to it:

Expand|Select|Wrap|Line Numbers
  1. Me.lblLocked.Visible = Not Me.lblLocked.Visible 
If you want it to flash more, then the first line can be increased to a higher number like:
Expand|Select|Wrap|Line Numbers
  1. If lngCount < 12 Then 
Everytime the lists get checked, lngCount gets reset to zero and it all starts over again.
Sep 17 '10 #6
doma23
107 100+
This line simply toggles the .Visible property by assigning it's opposite value to it
Yes, I never seen the syntax before and I thought that it should work the same as "me.lblLocked.visible = False" and that was confusing me.
Now it's perfectly clear.

If you want it to flash more, then the first line can be increased to a higher number like
Yeah, I just didn't understand why it doesn't flashes the number of times indicated, but basically twice less. So if you set lngcount < 10 it will flash 5 times, if it's set to 8 or 9 it will flash 4 times. Now, it's clear - because of the toggle effect:
0 - visible
1 - invisible
2 - visible
3 - invisible
4 - visible
and so on...
Sep 17 '10 #7
Megalog
378 Expert 256MB
0 - visible
1 - invisible
2 - visible
3 - invisible
4 - visible
Exactly how it works. "Me.lblLocked.Visible = Not Me.lblLocked.Visible" works by taking the current .visible value and applying the opposite. Thus each time the timer event activates it is toggling it on and off for as many times as it's allowed before it permanently stays visible.
Sep 17 '10 #8

Post your reply

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

Similar topics

2 posts views Thread by John Bowman | last post: by
4 posts views Thread by Mystery Man | last post: by
7 posts views Thread by Grigs | last post: by
4 posts views Thread by cashdeskmac | last post: by
8 posts views Thread by Arpan | last post: by
5 posts views Thread by BobLaughland | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.