HTA-based Date Calculator, First Gift to My Son.


My girlfriend was asking me several times before that she needs a handy tool to know how many days are before her due-date and in the future she needs to know our son’s age in the number of days.

This is an easy task for me, and I don’t want to use complex programming languages such as C++, C# because such programs need to be compiled. I don’t want to use Python in this case because my girlfriend dosn’t want to install any additional software. She will probably delete it sooner than you expect. In fact, her desktop is cleaner than the blu sky.

HTA is suitable for this task because most windows platforms support HTA. HTA stands for HTML Application, and in fact, it is purely a HTML page except that it has an extra tag <HTA:APPLICATION /> which specifies the attributes of the application, which you need to place it between the <head></head>

The HTA is small, but acts as a stand-alone application if you rename the file as *.hta extension. The HTA can be modified freely by using text-editor e.g. notepad. However, the source code is not protected. You can use [Script32] to protect the HTA source code.

The DateDiff function in VBScript can be used to compute the difference between two dates, based on that we can customise the message. For example,

eric HTA-based Date Calculator, First Gift to My Son. beginner code code library HTA implementation programming languages tools / utilities VBA vbscript windows

The HTA refreshes the output every 30 seconds, if the date changes.

eric2 HTA-based Date Calculator, First Gift to My Son. beginner code code library HTA implementation programming languages tools / utilities VBA vbscript windows

The HTA source code is given below, which you can modify freely e.g. customise messages etc. My girlfriend said the interface is ugly. 🙁 Most programmers do not like GUI design…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<html>
<head>
<title>Eric, How Old Are You?</title>
<HTA:APPLICATION
  APPLICATIONNAME="Eric"
  ID="EricLai"
  SCROLL="NO"
  MAXIMIZEBUTTON="NO"
  BORDER="THIN"
  VERSION="1.0"/>
</head>
 
<script language="VBScript">
Sub RefreshDate
    days = CInt(DateDiff("d", CDate(DueDate.Value), Now))
    msg.InnerHTML = ""
    If (days < 0) Then
        days = Abs(days)
        msg.InnerHTML = "Dear Eric Lai,<BR/> &nbsp; &nbsp; There are still " & "<B><font color='red'>" & days & "</font></B>" & " days to go. We cannot wait to meet you! <BR/> <BR /> Yours, <BR/>Mum & Dad"
    Else
        days = Abs(days)
        msg.InnerHTML = "Dear Eric Lai,<BR/> &nbsp; &nbsp; You are " & "<B><font color='red'>" & days & "</font></B>" & " days old. We love you! <BR/> <BR /> Yours, <BR/>Mum & Dad"
    End If
End Sub
 
Sub Window_OnLoad
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
    For Each objItem in colItems
        intHorizontal = objItem.ScreenWidth
        intVertical = objItem.ScreenHeight  
    Next
    width = 410
    height = 300
    If IsNull(intHorizontal) Then
        intHorizontal = 1024 'in case value cannot be obtained
    End If
    If IsNull(intVertical) Then
        intVertical = 800 'in case value cannot be obtained
    End If
    intLeft = CInt((intHorizontal - width) * 0.5)
    intTop = CInt((intVertical - height) * 0.5)
    window.resizeTo width, height
    window.moveTo intLeft, intTop
    RefreshDate
    iTimerID = window.setInterval("RefreshDate", 30000) ' refresh every 30 seconds
End Sub
</script>
 
<body bgcolor="white">
<div id="msg" style='font:30px'></div>
<input type="text" name="DueDate" style='display:none' id="DueDate" value="2012-8-13">
</body>
</html>
<html>
<head>
<title>Eric, How Old Are You?</title>
<HTA:APPLICATION
  APPLICATIONNAME="Eric"
  ID="EricLai"
  SCROLL="NO"
  MAXIMIZEBUTTON="NO"
  BORDER="THIN"
  VERSION="1.0"/>
</head>

<script language="VBScript">
Sub RefreshDate
    days = CInt(DateDiff("d", CDate(DueDate.Value), Now))
    msg.InnerHTML = ""
    If (days < 0) Then
    	days = Abs(days)
    	msg.InnerHTML = "Dear Eric Lai,<BR/> &nbsp; &nbsp; There are still " & "<B><font color='red'>" & days & "</font></B>" & " days to go. We cannot wait to meet you! <BR/> <BR /> Yours, <BR/>Mum & Dad"
    Else
    	days = Abs(days)
    	msg.InnerHTML = "Dear Eric Lai,<BR/> &nbsp; &nbsp; You are " & "<B><font color='red'>" & days & "</font></B>" & " days old. We love you! <BR/> <BR /> Yours, <BR/>Mum & Dad"
    End If
End Sub

Sub Window_OnLoad
	strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
    For Each objItem in colItems
    	intHorizontal = objItem.ScreenWidth
        intVertical = objItem.ScreenHeight	
    Next
    width = 410
    height = 300
    If IsNull(intHorizontal) Then
    	intHorizontal = 1024 'in case value cannot be obtained
    End If
    If IsNull(intVertical) Then
    	intVertical = 800 'in case value cannot be obtained
    End If
    intLeft = CInt((intHorizontal - width) * 0.5)
    intTop = CInt((intVertical - height) * 0.5)
    window.resizeTo width, height
    window.moveTo intLeft, intTop
    RefreshDate
    iTimerID = window.setInterval("RefreshDate", 30000) ' refresh every 30 seconds
End Sub
</script>

<body bgcolor="white">
<div id="msg" style='font:30px'></div>
<input type="text" name="DueDate" style='display:none' id="DueDate" value="2012-8-13">
</body>
</html>

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
696 words
Last Post: How Many Iterations to Compute e, the base of the Natural Log ?
Next Post: A SleepSort using Multiprocessing in BASH

The Permanent URL is: HTA-based Date Calculator, First Gift to My Son.

Leave a Reply