Results 1 to 15 of 15

Thread: Flashing label

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Flashing label

    i need to flashing (blinking) mylabel in red and blue... in this mode:

    init flashing

    my code

    end flashing

  2. #2
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Flashing label

    And as with 95% of Luca's posts i wouldn't be surprised if his requirement end's up being actually for VBA instead of vb6.....

    Code:
    'In a Standard-module "modTimer"
    
    Public Sub OnTimer()
        UserForm1.OnTimer
    End Sub
    
    'In a UserForm with 1 Label1, 2 CommandButtons
    Private nextTriggerTime As Date
    Private ColorBackup As Long
    Private TimerActive As Boolean
    
    Private Sub StartTimer()
        If Not TimerActive Then
            TimerActive = True
            ScheduleNextTrigger
        End If
    End Sub
    
    Private Sub StopTimer()
        If TimerActive Then
            TimerActive = False
            Application.OnTime nextTriggerTime, "modTimer.OnTimer", , False
        End If
    End Sub
    
    Private Sub ScheduleNextTrigger(Optional ByVal argTime As Long = 1)
    Dim Hours As Long
    Dim Minutes As Long
    Dim Seconds As Long
        If TimerActive Then
            If argTime > 0 Then
                If argTime < 60 Then
                    Seconds = argTime
                Else
                    Hours = argTime \ 3600
                    Seconds = argTime Mod 3600
                    Minutes = Seconds \ 60
                    Seconds = Seconds Mod 60
                End If
                nextTriggerTime = Now + TimeValue(Format(Hours, "00") & ":" & Format(Minutes, "00") & ":" & Format(Seconds, "00"))
                Application.OnTime nextTriggerTime, "modTimer.OnTimer"
            End If
        End If
    End Sub
    
    Public Sub OnTimer()
    Static stColor As Long
        If stColor = vbRed Then
            stColor = vbBlue
        Else
            stColor = vbRed
        End If
        Label1.BackColor = stColor
        ScheduleNextTrigger
    End Sub
    
    Private Sub CommandButton1_Click()  'Start the Timer
        ColorBackup = Label1.BackColor
        StartTimer
    End Sub
    
    Private Sub CommandButton2_Click()  'Stop the Timer
        StopTimer
        Label1.BackColor = ColorBackup
    End Sub
    
    Private Sub UserForm_Terminate()
        CommandButton2_Click
    End Sub
    Last edited by Zvoni; Aug 15th, 2018 at 05:29 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Flashing label

    I've decided that the luca90 account is some semi-public account that some VB6/VBA instructor gives out to his/her students.

    I've got no other explanation for the variety of expertise, grammer, and even knowledge of VBForums usage in the posts.

    Hmmm, or maybe it's passed around by the students, and the instructor doesn't know about it.

    It's definitely a strange thing, and often feels that we're doing homework.

    Y'all Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Flashing label

    Quote Originally Posted by Elroy View Post
    I've decided that the luca90 account is some semi-public account....It's definitely a strange thing, and often feels that we're doing homework.

    Y'all Take Care,
    Elroy
    Yup. I mean, his/her account was opened in 2005. Somebody with 13 years VB experience is in the wrong line of work if they can't make a label blink!
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: Flashing label

    For all my friend in this post.
    yes i'm on line from 13 year.
    But sure, my first work not is the programmer, I use in a few case VB 6.
    The first work in my offcie is an administrative role.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Flashing label

    Ahhh, Luca ... good to hear from you. And thanks for the bit of perspective.

    And yes, I'd probably use a timer too, as Zvoni illustrated.

    However, truth be told, I typically don't make labels (or other controls) that consistently blink. Most users think they're obnoxious. However, I do occasionally want to pull the attention toward something. Here's an example of where I do that:

    Code:
    
    Private Sub BlinkTheKineticsCheckbox()
        chkProcessKinetics.ForeColor = &HFF:                            chkProcessKinetics.Refresh
        Sleep 150
        chkProcessKinetics.ForeColor = chkProcessKinetics.BackColor:    chkProcessKinetics.Refresh
        Sleep 40
        chkProcessKinetics.ForeColor = &HFF:                            chkProcessKinetics.Refresh
        Sleep 150
        chkProcessKinetics.ForeColor = chkProcessKinetics.BackColor:    chkProcessKinetics.Refresh
        Sleep 40
        chkProcessKinetics.ForeColor = &HFF:                            chkProcessKinetics.Refresh
        Sleep 150
        chkProcessKinetics.ForeColor = chkProcessKinetics.BackColor:    chkProcessKinetics.Refresh
        Sleep 40
        chkProcessKinetics.ForeColor = &H0:                             chkProcessKinetics.Refresh
    End Sub
    
    

    I just call that anytime I want to pull attention to that chkProcessKinetics control.

    Here's the declaration for the Sleep API:

    Code:
    
    Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    
    

    Enjoy,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Flashing label

    And here, you encouraged me to make it more of a general purpose procedure:

    Code:
    
    Public Sub BlinkControl(ctl As Control, Optional iTimesToBlink As Long = 3, Optional iBlinkColor As Long = vbRed)
        Dim iOrigForeColor As Long
        Dim i As Long
        '
        '
        With ctl
            iOrigForeColor = .ForeColor
            For i = 1 To iTimesToBlink
                .ForeColor = iBlinkColor
                .Refresh
                Sleep 150
                .ForeColor = .BackColor
                .Refresh
                Sleep 40
            Next
            .ForeColor = iOrigForeColor
            .Refresh
        End With
    End Sub
    
    
    Enjoy,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Flashing label

    The original question lacks important detail. I suspect that what he wants is for that blinking activity to occur during some long-running thread-blocking code within an event handler.

  10. #10
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Flashing label

    Quote Originally Posted by Elroy View Post
    And yes, I'd probably use a timer too, as Zvoni illustrated.
    Eh?
    My code.snippet is actually in VBA, since VBA doesn't have a timer-control.
    If it's honest-to-god vb6 then slap a timer-control on your form, set your parameters for it. Done!
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  11. #11
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Flashing label

    Quote Originally Posted by dilettante View Post
    The original question lacks important detail. I suspect that what he wants is for that blinking activity to occur during some long-running thread-blocking code within an event handler.
    Wouldn't that mean DoEvents?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  12. #12
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: Flashing label

    Hi,

    I think Luca want's somthing in it's own Thread...

    if so Luca then read this http://www.desaware.com/tech/threading.aspx

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: Flashing label

    Quote Originally Posted by ChrisE View Post
    I think Luca want's somthing in it's own Thread...
    *chuckles*

    Chris, I can't tell if you're being serious or facetious.

    Either way, I don't think Luca is quite ready for multi-threading.

    Quote Originally Posted by Zvoni View Post
    Wouldn't that mean DoEvents?
    If Luca is willing to splatter a blinking call (with .Refresh) around in his long-running-procedure, it wouldn't necessarily mean using DoEvents. However, if he uses Sleep, it would certainly put a hit on the performance of that long-running-procedure. But there are other approaches that could be considered (maybe just a toggle for the forecolor in the long-running procedure).


    So Luca, as Dilettante suggests, how about a few more details on what you're thinking.

    All The Best,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  14. #14
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: Flashing label

    Quote Originally Posted by Elroy View Post
    *chuckles*

    Chris, I can't tell if you're being serious or facetious.

    Either way, I don't think Luca is quite ready for multi-threading.



    If Luca is willing to splatter a blinking call (with .Refresh) around in his long-running-procedure, it wouldn't necessarily mean using DoEvents. However, if he uses Sleep, it would certainly put a hit on the performance of that long-running-procedure. But there are other approaches that could be considered (maybe just a toggle for the forecolor in the long-running procedure).


    So Luca, as Dilettante suggests, how about a few more details on what you're thinking.

    All The Best,
    Elroy
    Hi Elroy,

    well Luca will have to explain what --myCode-- is going to do

    i need to flashing (blinking) mylabel in red and blue... in this mode:

    init flashing

    my code

    end flashing
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  15. #15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width