-
Aug 15th, 2018, 02:13 AM
#1
Thread Starter
PowerPoster
Flashing label
i need to flashing (blinking) mylabel in red and blue... in this mode:
init flashing
my code
end flashing
-
Aug 15th, 2018, 04:33 AM
#2
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Aug 15th, 2018, 04:50 AM
#3
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
-
Aug 15th, 2018, 08:13 AM
#4
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.
-
Aug 15th, 2018, 08:24 AM
#5
Re: Flashing label
Originally Posted by Elroy
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
-
Aug 15th, 2018, 10:29 AM
#6
Thread Starter
PowerPoster
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.
-
Aug 15th, 2018, 10:39 AM
#7
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.
-
Aug 15th, 2018, 10:49 AM
#8
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.
-
Aug 15th, 2018, 12:01 PM
#9
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.
-
Aug 15th, 2018, 12:19 PM
#10
Re: Flashing label
Originally Posted by Elroy
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
-
Aug 15th, 2018, 12:20 PM
#11
Re: Flashing label
Originally Posted by dilettante
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
-
Aug 15th, 2018, 12:29 PM
#12
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.
-
Aug 15th, 2018, 12:36 PM
#13
Re: Flashing label
Originally Posted by ChrisE
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.
Originally Posted by Zvoni
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.
-
Aug 15th, 2018, 12:50 PM
#14
Re: Flashing label
Originally Posted by Elroy
*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.
-
Aug 15th, 2018, 01:03 PM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|