How to Make a Clock in Visual Basic

Computers running Windows come with a clock in the system tray in the lower right-hand corner of your screen. If you're running Windows Vista, you can add a clock to your Windows Sidebar. If these clocks don't fill your needs or appeal to you visually, you can make your own with Microsoft's Visual Basic. A few simple objects that will allow you to make a clock and make it appear in whatever format you like.

Things You'll Need

  • PC
  • Visual Basic
Show More

Instructions

    • 1

      Obtain a copy of Visual Basic and install the software on your computer. Visual Basic is an application that is manufactured by Microsoft and can be purchased at online or at a computer store. It is only available for users of the Windows operating system.

    • 2

      Create a new Visual Basic blank application. Click on "File", then "New". From the window that opens, select a "new blank exe application".

    • 3

      Add text boxes to contain the digits for the clock. Add one text box for the hour, one for the minute, and one for the seconds. To add a text box, double click on the text box control in the toolbox. This control is a button with a large letter "A" on it.

    • 4

      Add a timer control to the form. This control looks like a small stopwatch in the toolbox. Double click on it to add it to the form. Set the interval property of the control to 1,000 so that the code for the control will execute once per second.

    • 5

      Add code for the timer control. To add the code, double-click on the timer control in the main window. In the code window for the timer control, access the Now function to update the controls. Use the left and mid functions to access each part. For example, to set the hours, use txtHours.text = left(Now(), 2). To calculate the minutes, use txtMinutes.text = mid(Now(),4,2). To set the seconds, use txtSeconds.text = mid(Now(),7,2).

    • 6

      Run the program to check your code. Be sure the timer is enabled or the program will do nothing.

Tips & Warnings

  • Change the format and layout of your text boxes to make the appearance what you want. You can add buttons, alarms, and other features once your basic clock is set up.

Related Searches:

Comments

You May Also Like

Related Ads

Featured