NewTimer

Description

Adds a timer control to a form

Syntax

[Set oCtl =] oFrm.NewTimer ( Name, Seconds )

Parameters

Part

Description

Set oCtl =

(optional) Store a reference to the new control in the variable oCtl. This variable can be used to access the control's properties and methods.

oFrm

A reference to a form object (see the NewForm method)

Name

The name of the control. It must be unique within the form and may not be empty or start with an asterisk (*)

Seconds

The interval in seconds between calls to the user's event handler

Properties and Events

Property

Description

Enabled

(boolean) Determines whether the control responds to the passage of time

Interval

The number of milliseconds between calls to the control's Timer event.

0

Disables the timer

1 - 65535

Sets an interval with a maximum of 65535 milliseconds

WshDialog uses an extra internal counter in combination with the interval property to allow for intervals greater than 65535 milliseconds. Therefore you should not modify the Interval property directly, but use the NewTimerInterval function instead

Parent

(read-only) Returns the parent form, object or collection. You can use the parent property to access the properties and methods of an object's parent

Tag

(reserved) Used internally to store the user-defined controlname and the countdown state

Event

Description

Event raised

Timer

Occurs when the timer interval has passed

Controlname

To be able to handle events you need to operate a form in callback mode.
This subject is described in the following topics:
Callback forms, ClickHandler

Remarks

1.

Although timer controls are added to forms, and thus appear to be part of a form, they are not disabled or destroyed with them. Even after destroying a form it's timer(s) live on ! You must set its Enabled property to False to get rid of a timer.

2.

Timers will be delayed by the time you spend in the event handler

Example

Option Explicit

Const vbModal = 1

Dim oDlg, oFrm, oCtl

'Create the WshDialog.Kit object and store a reference in oDlg
Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")

'Add a new form and store a reference to it in the variable oFrm
Set oFrm = oDlg.NewForm("Sample")

'Add a progressbar control and store a reference in the variable oCtl
Set oCtl = oFrm.NewProgressBar("BAR1", 150, 100, 2450, 250, 0, 100, 0)

'Add a timer with an interval of 1 second
oFrm.
NewTimer "TIMER", 1

'Automatically size the form and enable event handling (callback)
oFrm.Autosize
oFrm.CallBack = True

'Show the form (modally)
oFrm.Show vbModal

MsgBox "Done"

'--------------------------------------------------------------------------------------------------
' oDlg_ClickHandler handles the events sent by the controls
'--------------------------------------------------------------------------------------------------
Sub oDlg_ClickHandler(sForm, sControl)

    Dim oFrm, oCtl, oBar


    
'Get a reference to the form and the control that raised the event
    Set oFrm = oDlg.Frm(sForm)
    Set oCtl = oFrm.Ctl(sControl)

    
'Check which control caused the event
    Select Case sControl
    Case
"TIMER"
        
'Move the progressbar by 5 percent
        Set oBar = oFrm.Ctl("BAR1")
        If oBar.Value < oBar.Max Then
            oBar.Value = oBar.Value + Cint((oBar.Max - oBar.Min) / 20)
        Else
            
'Maximum reached. Disable the timer and dismiss the form
            oCtl.Enabled = False
            oFrm.Hide
        End If
    Case Else
    
'Ignore all other events. Do NOT use oFrm.Hide here,
    'or any event not handled above will dismiss the form
    End Select

End Sub