Solved

BLINKING TEXT

Posted on 1999-01-18
3
930 Views
Last Modified: 2008-03-17
How do I nake the text in a textbox or label blink off and on without using a timer to control it?
0
Comment
Question by:opchan
  • 3
3 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 50 total points
ID: 1469220
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 1469221
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 1469222
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now