NewFileListBox

Description

Adds a file listbox control to a form.

Syntax

[Set oCtl =] oFrm.NewFileListBox

( Name, Left, Top, Width, Height, [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

Container

(optional) The name of an existing frame control that will act as container for the listbox. 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, Methods and Events

Property

Description

Archive

(boolean) Show or hide files with the Archive atrribute (true by default)

BackColor

Background color (use the RGB function to assign a color value)

Enabled

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

Filename

Returns or sets the path and filename of a selected file

Returns the currently selected filename from the list (the path is retrieved separately, using the Path property). The value is functionally equivalent to List(ListIndex). Returns a zero-length string if no file is selected

When setting this property :

Including a drive, path, or pattern in the string changes the settings of the Drive, Path, and Pattern properties accordingly

Including the name of an existing file (without wildcard characters) in the string selects the file

Changing this property may also cause one or more ot these events: PathChange (if you change the path), PatternChange (if you change the pattern), or DblClick (if you assign an existing filename)

This property setting can be a qualified network path and filename, using the following syntax : \\servername\sharename\pathname

Fontname

The font used to display text. The default is determined by the system. Check the glossary for an explanation about setting font properties.

Fontsize

The size of the font in points. The maximum is 2160 points.

Fontbold

(boolean) Enable or disable the bold style of a font

Fontitalic

(boolean) Enable or disable the italic style of a font

Fontstrikethru

(boolean) Enable or disable the strikethru style of a font

Fontunderline

(boolean) Enable or disable the underline style of a font

ForeColor

Foreground color (use the RGB function to assign a color value)

Height

The height of the control in twips

Hidden

(boolean) Show or hide files with the Hidden atrribute (false by default)

Left

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

List (index)

(read-only) The filename at the specified index. The first item has index 0 and the index of the last item is ListCount – 1.

ListCount

(read-only) The number of subdirectories in the current directory

ListIndex

(integer) Returns or set the index of the currently selected file in the list. However, because MultiSelect is enabled for this control, ListIndex returns the index of the item contained within the focus rectangle, whether or not the item is actually selected. You should use the Selected property instead!

-1

Indicates no file is currently selected

n

(default) A number indicating the index of the currently selected file

MultiSelect

(read-only) Returns 2 to indicate that extended multiple selection (using the shift and control keys to select or deselect files) is allowed

Normal

(boolean) Show or hide files with the Normal atrribute (true by default)

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

Path

(string) Returns or sets the current path. The default is the current path when the control is created at run time. Setting the Path property has effects on a control similar to the MS-DOS ChDir command. Relative paths are allowed with or without a drive specification. Specifying only a drive with a colon (:) selects the current directory on that drive.

The Path property can also be set to a qualified network path without a drive connection using the following syntax: \\servername\sharename\path

This syntax changes the Drive property to a zero-length string ("").

Pattern

(string) A file specification which determines which files are displayed. The default is "*.*", which returns a list of all files. In addition to using wildcard characters, you can also use multiple patterns separated by semicolons (;)

Readonly

(boolean) Show or hide files with the Readonly atrribute (true by default)

Selected (index)

(boolean) Returns or sets the selection status of a file at the specified index in the list. Because the MultiSelect property is set, you should use this property instead of List(ListIndex)

System

(boolean) Show or hide files with the System atrribute (false by default)

TabStop

(boolean) Determines whether the TAB key can be used to move the focus

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

TopIndex

(integer) The index of the item displayed in the topmost position

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

Refresh

Forces a complete repaint of a control

SetFocus

Moves the focus to the specified control

Event

Description

Event raised

DblClick

Occurs when the user double-clicks a file in the control

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

Example

Option Explicit

Const vbModal = 1

Dim oDlg, oFrm

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

'Call BuildForm to build the form and store a reference in oFrm
Set oFrm = BuildForm

'Show the Replicator form
oFrm.Show vbModal

'--------------------------------------------------------------------------------------------------
' The BuildForm function builds the form and returns a reference to it
'--------------------------------------------------------------------------------------------------
Function BuildForm

    Dim oFrm, oCtl

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

    'Create a button to read the selected files from the file listbox control
    oFrm.NewButton "Selected", 4000, 300, 2000, 375, "&Show Selected File(s)"

    'Add a drive and directory listbox control
    oFrm.NewDriveListBox "DRV1", 350, 300, 2000
    oFrm.NewDirListBox "DIR1", 350, 800, 3200, 2000

    'Add a file listbox control and set it's Pattern property to show only DLL's
    Set oCtl = oFrm.NewFileListBox("FIL1", 4000, 800, 3200, 2000)
    oCtl.Pattern = "*.DLL"

    'Set the form's caption
    oFrm.Caption = "Testing Drive, Directory and File Listboxes"

    'Automatically size the form to the controls placed on it
    oFrm.AutoSize

    'Show the form in the taskbar
    oFrm.TaskBar = True

    'Enable event handling (callback) for this form
    oFrm.CallBack = True

    'Return the form object
    Set BuildForm = oFrm

End Function

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

    Dim oFrm, oCtl

    
'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 UCase(sControl)
    Case "DRV1"
        
'The change event occured for the DRV1 drive listbox control
        'Set the Path property of the DIR1 directory listbox to the currently selected drive
        On Error Resume Next
        oFrm.Ctl("DIR1").Path = oCtl.List(oCtl.ListIndex)
    Case "DIR1"
        
'The change event occured for the DIR1 directory listbox control
        'Set the Path property of the FIL1 file listbox to the currently selected directory
        On Error Resume Next
        oFrm.Ctl("FIL1").Path = oCtl.List(oCtl.ListIndex)
    Case "FIL1"
        
'The DblClick event occured for the FIL1 file listbox control
        
'Show a messagebox with the file that was double-clicked
        MsgBox "File : " & oCtl.List(oCtl.ListIndex), , "Double-clicked"
    Case "SELECTED"
        
'The Show Selected File(s) button was clicked
        Dim oCtlFiles, sFiles, X
        
'Get a reference to FIL1 file listbox control
        Set oCtlFiles = oFrm.Ctl("FIL1")
        
'Loop through all the items (files) in the file listbox control
        For X = 0 To oCtlFiles.ListCount - 1
            
'Check each file's Selected property
            If oCtlFiles.Selected(X) Then
                
'When selected, add it's name to the sFiles string
                sFiles = sFiles & oCtlFiles.List(X) & vbCrLf
            End If
        Next
        
'Show a messagebox with all the selected files
        MsgBox sFiles, , "Selected file(s)"
    Case "*CLOSE"
        
'The closebox was clicked. Dismiss the form (hide it)
        oFrm.Hide
    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