YasserKhalil
PlatinumLounger
Posts: 4913 Joined: 31 Aug 2016, 09:02
Post
by YasserKhalil » 29 Mar 2020, 17:35
Hello everyone
I am trying the following code that blinks the textbox4 if it equals to date
Code: Select all
Private Sub TextBox4_AfterUpdate()
Static b As Boolean
Static i As Integer
With TextBox4
If Not IsDate(.Text) Then Exit Sub
If CDate(.Text) = Date Then
Do Until i >= 5
If b Then .BackColor = vbYellow Else .BackColor = vbGreen
Application.Wait Now + TimeValue("00:00:01")
b = Not b
i = i + 1
Debug.Print i
Loop
b = False: i = 0
End If
End With
End Sub
I put the variable i to 5 so I expect to see the blinking 5 times but I just noticed it twice not more. Any idea how this can be fixed?
HansV
Administrator
Posts: 78483 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 29 Mar 2020, 18:04
Insert the following line above the Application.Wait line:
This forces the userform to be updated.
Warning: in general, making interface elements blink is not recommended; it might irritate users or even have an adverse effect.
Best wishes,
Hans
YasserKhalil
PlatinumLounger
Posts: 4913 Joined: 31 Aug 2016, 09:02
Post
by YasserKhalil » 29 Mar 2020, 18:33
Thanks a lot for the advice. I tested using RePaint but I got just blinking three times instead of five times.
HansV
Administrator
Posts: 78483 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 29 Mar 2020, 18:53
When I enter today's date, the text box becomes green, yellow, green, yellow and finally green.
Best wishes,
Hans
HansV
Administrator
Posts: 78483 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 29 Mar 2020, 19:03
Here is a low-quality video (zipped) of what I see:
Clip.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
YasserKhalil
PlatinumLounger
Posts: 4913 Joined: 31 Aug 2016, 09:02
Post
by YasserKhalil » 29 Mar 2020, 19:17
Yes that's what I am talking about. The variable i equals to 5 so I expect 5 times or I think I missed it must be 10 so as to get this blinking 5 times.
Thanks a lot Mr. Hans for great help.
HansV
Administrator
Posts: 78483 Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands
Post
by HansV » 29 Mar 2020, 19:37
Do Until i >= 5 will get you 5 color changes. If you want 5 times green AND yellow, you must indeed use Do Until i >= 10.
Best wishes,
Hans
YasserKhalil
PlatinumLounger
Posts: 4913 Joined: 31 Aug 2016, 09:02
Post
by YasserKhalil » 29 Mar 2020, 19:40
Yes I recognized that when I posted the last reply
Thank you very much for your helpful and great support