Making label control flash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doma23
    New Member
    • May 2010
    • 107

    Making label control flash

    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:

    Code:
    If Form_frmMain.cbo1.ListCount = 1 and Form_frmmain.cbo2.ListCount = 1 and.... Then
    HOLD NEXT LINE FOR ONE SECOND
    Form_frmMain.TimerInterval = 200
    AFTER ONE SECOND DO THIS
    Form_frmMain.TimerInterval = 0
    Form_frmMain.lblLocked.Visible = True
    End If
    Tnx!
  • munkee
    Contributor
    • Feb 2010
    • 374

    #2
    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.

    Code:
    Private Sub Command74_Click()
    Dim currenttime As Date
    currenttime = Now()
    Do
    Loop While Now() < currenttime + TimeSerial(0, 0, 5)
    MsgBox "5 seconds done"
    End Sub

    Comment

    • doma23
      New Member
      • May 2010
      • 107

      #3
      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.Visi ble=True" in one and then "lblLocked.Visi ble=True" in next.
      Although it's not satisfying solution, I just wanted to test it, and it didn't work.

      Comment

      • Megalog
        Recognized Expert Contributor
        • Sep 2007
        • 378

        #4
        Code:
        Option Compare Database
        Option Explicit
        
        Public lngCount As Long
        
        'The AfterUpdate events from whatever control you 
        'want this to activate on. Duplicate this for each 
        'combo/list control
        
        Private Sub cbo1_AfterUpdate()
            Call CheckLists
        End Sub
        
        Private Sub cbo2_AfterUpdate()
            Call CheckLists
        End Sub
        
        
        Private Sub CheckLists()
        'This checks the criteria (Listcounts) and 
        'sets the timer off if it matches, otherwise 
        'hides the possibly visible label.
        
            lngCount = 0
            If Form_frmMain.cbo1.ListCount = 1 and Form_frmmain.cbo2.ListCount = 1 and.... Then
                Me.TimerInterval = 250
            Else
                Me.lblLocked.Visible = False
            End If
        
        End Sub
        
        Private Sub Form_Timer()
        'Timer event itself.  Flashes on and off 6 times,
        'then turns the interval off and leaves the label visible.
        
            If lngCount < 6 Then
                Me.lblLocked.Visible = Not Me.lblLocked.Visible
                lngCount = lngCount + 1
            Else
                Me.lblLocked.Visible = True
                Me.TimerInterval = 0
            End If
        
        End Sub

        Comment

        • doma23
          New Member
          • May 2010
          • 107

          #5
          @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.vi sible = not me.lbllocked.vi sible

          I don't fully understand it.

          Comment

          • Megalog
            Recognized Expert Contributor
            • Sep 2007
            • 378

            #6
            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:

            Code:
            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:
            Code:
            If lngCount < 12 Then
            Everytime the lists get checked, lngCount gets reset to zero and it all starts over again.

            Comment

            • doma23
              New Member
              • May 2010
              • 107

              #7
              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.v isible = 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...

              Comment

              • Megalog
                Recognized Expert Contributor
                • Sep 2007
                • 378

                #8
                0 - visible
                1 - invisible
                2 - visible
                3 - invisible
                4 - visible
                Exactly how it works. "Me.lblLocked.V isible = Not Me.lblLocked.Vi sible" 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.

                Comment

                Working...