Progressive Clock

Introduction

In this example, we will display the current time of the computer using progress bars. A dialog box will be equipped with these controls that each receives its value from the computer and displays the value graphically.

  1. Start Microsoft Visual Basic and create a Standard EXE application
  2. Save the application in a new folder named Progress Clock
  3. Save the form as frmMain and save the project as ProgressClock
  4. To use the needed progress bars, on the main menu, click Project -> Components...
  5. In the Components dialog box, click the Microsoft Windows Common Controls 6.0 (SP4) check box
     
  6. Click OK
  7. Design it as follows
     
    Control Properties
    Form Name: frmMain
    Border Style: 3 - FixedDialog
    Caption: Progressive Clock
    Timer Interval: 20
    Label Caption: Time
    Label Caption: Hours:
    Progress Bar Name: prgHours
    Max: 23
    Label Name: lblHours
    Caption: 000
    Label Caption: Minutes:
    Progress Bar Name: pgrMinutes
    Max: 59
    Label Name: lblMinutes
    Caption: 000
    Label Caption: Seconds
    Progress Bar Name: pgrSeconds
    Max: 59
    Label Name: lblSeconds
    Caption: 000
  8. Double-click the Timer control and implement its OnTimer event as follows:
     
    Private Sub Timer1_Timer()
        Dim CurTime As Date
        Dim ValHours As Integer
        Dim ValMinutes As Integer
        Dim ValSeconds As Integer
        
        CurTime = Time
        ValHours = Hour(CurTime)
        ValMinutes = Minute(CurTime)
        ValSeconds = Second(CurTime)
        
        pgrHours.Value = ValHours
        pgrMinutes.Value = ValMinutes
        pgrSeconds.Value = ValSeconds
        
        lblHours.Caption = CStr(ValHours)
        lblMinutes.Caption = ValMinutes
        lblSeconds.Caption = CStr(ValSeconds)
    End Sub
  9. Test the application
 
 

Copyright © 2004-2014 FunctionX, Inc. FunctionX