NewProgressBar

Description

Adds a progressbar control to a form

Syntax

[Set oCtl =] oFrm.NewProgressBar

( Name, Left, Top, Width, Height, Min, Max, [Value], [Container] )

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 (*)

Left

See the list of properties below

Top

See the list of properties below

Width

See the list of properties below

Height

See the list of properties below

Min

See the list of properties below

Max

See the list of properties below

Value

(optional) See the list of properties below

Container

(optional) The name of an existing frame control that will act as container for the progressbar. If unspecified or an empty string, the Form itself will be the container. Please note that the Left and Top properties are relative to the container's left and top edges

Properties and Methods

Property

Description

Align

0

The controls size and location can be set in code (default)

For all other Align values below, the width of the control is equal to the forms Scalewidth property (see the NewForm method).
Furthermore, with values 1 and 2 the control will be automatically sized

1

The control will be positioned at the top of the form

2

The control will be positioned at the bottom of the form

3

The control will be positioned at the left op of the form

4

The control will be positioned at the right of the form

BorderStyle

0

No border (default)

1

Fixed single

Enabled

(boolean) Determines if the control can respond to user-generated events

Height

The height of the control in twips

Left

The distance from the left edge of the specified container in twips

Max

The maximum value of the range (default 100, maximum 32767)

Min

The minimum value of the range (default 0, maximum 32767)

Orientation

0

Horizontal (default)

1

Vertical

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

Scrolling

0

Segmented scrolling (default)

1

Smooth (solid) scrolling

Tag

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

ToolTipText

Explanatory text that appears in a small rectangle below the object when you pause the mouse pointer (hover) over it for about one second

Top

The distance from the top edge of the specified container in twips

Value

(integer) Indicates an operation's approximate progress toward completion. Value must be in the range between the Min and Max properties, inclusive

Visible

(boolean) Determines whether the control is visible or hidden

Width

The width of the control in twips

Method

Description

Move

Parameters: left [, top [, width [, height ]]]

Only the left argument is required. However, to specify any other arguments, you must specify all arguments that appear in the syntax before the argument you want to specify. For example, you can't specify width without specifying left and top. Any trailing arguments that are unspecified remain unchanged

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