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.
|
|
- Start Microsoft Visual Basic and create a Standard EXE application
- Save the application in a new folder named Progress Clock
- Save the form as frmMain and save the project as ProgressClock
- To use the needed progress bars, on the main menu, click Project ->
Components...
- In the Components dialog box, click the Microsoft Windows Common
Controls 6.0 (SP4) check box
- Click OK
- 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 |
|
- 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
|
- Test the application
|
|
|