AdvancedHMI Software
General Category => Support Questions => Topic started by: ASF on March 06, 2017, 10:58:18 PM
-
Hi,
I have a VBA sub which, when a button is clicked, gets a value from a text file and writes it to the PLC. This text file is updated at 5:30am every day, so what I would like is for this VBA sub to run automatically every day at 6am, so that my value is automatically updated every day, whether or not I click the button.
Is there any way of triggering a VBA sub based on time of day?
I have an always-updating, hidden form that sits out of sight and handles all of my background tasks like this, so there's no issues with which form is open at 6am, and the code itself is working - all I need is a way of triggering it.
I could put a data subscriber on the hidden form and monitor the PLC's RTC, and watch for it being "6", but I'm hoping there's a cleaner way...
Thanks!
-
- Add a timer to the form
- Set Interval to 31000
- Set Enabled to True
- Double click the timer to get back to the code
- Enter code similar to this:
If Now.Hour = 6 And Now.Minute = 0 Then
'* call you code here
End If
-
Thanks, I'll give that a try.
I assume that the timer is a self-resetting timer, and the interval (31000) is 31 seconds?
-
Yes, it will continue to fire every 31 seconds.
-
Thanks Archie, that works.