As a programmer, you have to face the computer for a long time in the process of learning or working. Sometimes you forget to rest or drink water. Sometimes you sit for hours.
This is very harmful to health. I didn’t care much about it before. I usually drink water when I’m thirsty. It wasn’t until recently that I felt a little uncomfortable in my throat, possibly inflamed, that I realized it was a sign of protest inside my body.
In fact, when you feel thirsty, your body is very short of water.Therefore, we should drink water regularly, usually at intervals.
Alarm clock or countdown
But for many people, it’s hard to get the brain’s automatic conditioning to drink water. So we need to remind us by external means.
There are many ways to remind people, such as setting a few alarm clocks or counting down. Unfortunately, there is also a drawback in this way of using mobile phones. Sometimes, if you are too focused on your work and don’t have time to watch your mobile phone, the alarm clock and countdown will be invalid.
Write reminders using scripts
Therefore, in order to better solve the above problems, we can proceed from the essence. Generally speaking, programmers have more time to face the computer when they work a day, so we can write a timed task on the computer.
My approach is
WindowsWrite on the system
VBScript scriptEvery once in a while, play the window to remind me to drink water.
This article mainly introduces how to be in the
WindowsSystem under use
VBScriptWrite a simple timer window.
If it is
MacbookYou can use it.
LinuxThe system can be used
What is VBScript
VBScriptIt is a scripting language developed by Microsoft.
VBScriptYes, you can.
WindowsWrite automatic tasks under the system and so on.
WindowsUnder the system, you can double-click directly, and the code is run by
wscript.exeResponsible for interpretation and execution.
I didn’t learn it systematically before I wrote this pop-up window widget.
VBScriptNow I have learned to use it, but I have only learned it roughly. If you want to understand it systematically, you can take a look at the novice bird tutorial.
VBScript Knowledge Used
This gadget is actually very simple, the core is just a few lines of code, similar to the web page.
setIntervalAnd then as soon as the time comes
Here’s a detailed description of what’s used in the code
Dim variableNameDefine variables
Do ... LoopCirculation, similar
do ... while(true)
If ... Then ... Else ... End IfConditional structure
InputBoxSimilar to the web page
MsgBoxSimilar to the web page
The following is the full code of the tool.
Dim interval Dim ret ' set task's interval Do interval = InputBox("Please input the interval:", "Interval(seconds)", 30 * 60 * 1000) If interval = vbEmpty Then ' click cancel MsgBox "You input empty, interval is set default half an hour." interval = 1800000 Exit Do End If If Not IsNumeric(interval) Then ' input what is't a numeric MsgBox "Please input number" Else Exit Do End If Loop ' execute interval task Do ret = MsgBox("Drink some water", vbOKCancel, "Time up") If ret = 1 Then Wscript.sleep interval Else MsgBox "Close notification", vbOkOnly, "Close notification" Exit Do End If Loop
Sometimes it’s interesting to find that programming can be used in everyday life.
Attached at the end of the project
Star or ForkThank you for your support.