• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 957
  • Last Modified:

BLINKING TEXT

How do I nake the text in a textbox or label blink off and on without using a timer to control it?
0
opchan
Asked:
opchan
  • 3
1 Solution
 
caraf_gCommented:
OK, if it MUST be done without a timer....

Create a form with two labels, label1 and label2

Make Label2 invisible, and give Label1 a caption

Create two picture boxes in a control array Picture1(0) and Picture1(1)

Paste the following code into the form module:
Option Explicit
Private datLastTime As Date
Private Sub Picture1_GotFocus(Index As Integer)

Dim dblSecond As Double

dblSecond = (Now - datLastTime) * 24 * 60 * 60
Do While dblSecond <= 0.5
    DoEvents
    dblSecond = (Now - datLastTime) * 24 * 60 * 60
Loop
datLastTime = Now

If Label1.Caption = "" Then
    Label1.Caption = Label2.Caption
    Label2.Caption = ""
Else
    Label2.Caption = Label1.Caption
    Label1.Caption = ""
End If


DoEvents
If Visible Then
    Picture1(1 - Index).SetFocus
Else
    Unload Me
End If

End Sub

0
 
caraf_gCommented:
But this only works if there are no other controls on the form that can receive focus so really it is only a gimmicky solution.
0
 
caraf_gCommented:
Alternative solution - much better!

Create a form with two labels, label1 and label2

Make Label2 invisible, and give Label1 a caption

Paste the following code into the form module:
Option Explicit
Private datLastTime As Date
Private blnUnloading As Boolean
Private Sub Form_Activate()

Dim dblSecond As Double

Do While Not blnUnloading
    dblSecond = (Now - datLastTime) * 24 * 60 * 60
    Do While dblSecond <= 0.5
        DoEvents
        If blnUnloading Then
            Exit Sub
        End If
        dblSecond = (Now - datLastTime) * 24 * 60 * 60
    Loop
    datLastTime = Now

    DoEvents
    If blnUnloading Then
        Exit Sub
    End If
    If Label1.Caption = "" Then
        Label1.Caption = Label2.Caption
        Label2.Caption = ""
    Else
        Label2.Caption = Label1.Caption
        Label1.Caption = ""
    End If
Loop

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

blnUnloading = True

End Sub

With the above code, your form can even have other controls and they can have focus. Not nearly as gimmicky as previous solution!

Good luck!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now