Visual Basic countdown

Theo Hupkens

You can make a countdown program yourself with Visual Basic. In its simplest version you only have to type one line of program code yourself. The program described here counts down to January 1, 2100. You can modify this program to use any other date (marriage, retirement, reaching age of consent…). Also, you could modify the program to count down in days, hours or minutes instead of seconds.

Design phase Running (not now!)

To make this program do the following: Create a new application and place a textbox component on its form. Place a Timer component on the form and double-click on it. Visual Basic already generates two lines of code for the OnTimer event handler. Complete the code as shown below.

Private Sub Timer1_Timer()

Text1.Text = FormatNumber(24# * 3600 * (DateSerial(2100, 1, 1) - Now), standard)

End Sub

Set the Timer interval property to 1000 or less (but NOT to zero). After this the program is ready to run! The # after the 24 make this a long integer. This prevents an overflow error. Just as in the Delphi version, the result is not corrected for daylight saving settings. (It's hard to say whether this is good or bad.)

The program was tested using Visual Basic 6.

 

Last modified: August 17, 2000