Bern
Bern

Reputation: 11

Creating and setting of labels to 'blink' at different timing interval in visual basic 6

As my title mentioned, I need help to solve this problem. Just some additional info, I don't intend to use any command button. I just want to solely rely on the timer. I also want the labels to stop 'blinking' and be visible after 20 sec. I have provided my code. I definitely know there are problems in my coding as I'm new to VB and am still learning. Hope anyone here is able to help. Thank you very much.(By the way, please pardon me and let me know if I make any mistake in creating a thread as I'm a new user.)

Private Sub tmrBlink_Timer()
Dim i%
i = i + 1

Do 
    lblBlink1Sec.Visible = Not lblBlink1Sec.Visible
    Do
        tmrBlink.Interval = 2000
        lblBlink2Sec.Visible = Not lblBlink2Sec.Visible
    Loop Until i <= 10
        Do
            tmrBlink.Interval = 5000 
            lblBlink5Sec.Visible = Not lblBlink5Sec.Visible
        Loop Until i <= 4
Loop Until i <= 20

End Sub

Upvotes: 1

Views: 1356

Answers (2)

Bern
Bern

Reputation: 11

Thank you Thomas, Jac and Anish for the advice and feedback. Just that my answer is halfway answered. Maybe my question wasn't clear enough. I need to make 3 labels 'blink' at 1 sec, 2 sec and 5 sec respectively and stop 'blinking' but be visible after 20 seconds.

If a Mod 2 = 0 Then  'Check whether the value of the counter is odd or even?
    Label1.Visible = True
    Label2.Visible = Not Label2.Visible
    Label5.visible = True
    Elseif a Mod 5 = 0 Then
        Label1.Visible = True
        Label2.Visible = True
        Label5.Visible = Not Label5.Visible
            Else 
                Label1.Visible = Not Label1.Visible
                Label2.Visible = True
                Label5.Visible = True    
End If
a = a + 1            'Increment the counter
If a = 20 Then 
   Timer1.Enabled = False 'code to stop your blinking after 20 seconds
   label1.Visible = True
   Label2.Visible = True
   Label5.Visible = True  
End if
End Sub

I have modified the code a bit and used label1,2,5 to represent the timing I need it to 'blink'. Please give me some feedback on the coding. Thank you very much. :)

Upvotes: 0

Anish Sharma
Anish Sharma

Reputation: 505

Well i would like you to look at the following piece of code.

Private Sub Timer1_Timer()
Static a As Integer 'A counter which will not be reinitialized
If a Mod 2 = 0 Then  'Check whether the value of the counter is odd or even?
    Label1.Visible = True
Else: Label1.Visible = False
End If
a = a + 1            'Increment the counter
If a = 20 Then 
     Timer1.Enabled = False 'code to stop your blikning after 20 seconds
     label1.visible=false
end if
End Sub

There is a variable a associated with your every timer interval. after every timer interval, it will be incremented and will toggle between odd and even values.

Upvotes: 1

Related Questions