# fileview

`FILEVIEW` is a sample program that demonstrates how to insert the Viewing ActiveX control into a Visual Basic application and use it to display documents.

## Create a New Visual Basic Project 6.0

1. Start a new project by choosing New Project from the File menu.

2. Add the Viewing Control to the project. From the Project menu, select Components.

3. In the Components dialog box, select KeyView OLE Control module from the Controls list box. Click OK.

   If the KeyView OLE Control module is not listed in the Controls list box, click Browse to locate and register the control.

   The Viewing icon appears in the Toolbox.

## Draw the Controls

Draw the controls on the form according to the diagram above. Use the following controls:

Button | Control
--- | ---
| Command button
| Label
| Drive list box
| Directory list box
| File list box
| Viewing control

## Set Objects and Properties

After you design the form, you need to set the following properties:

Object | Property | Setting
--- | --- | ---
Form | Caption | File Viewer
Label | BorderStyle Caption | 1-Fixed Single (Empty)
Command button | Caption | Exit

NOTE: Use the default settings for all other properties and objects.

## Create Event Procedures

In the File Viewer application, create the following event procedures for five different controls. After you have completed these event procedures, you can compile and run the application.

Form Load event: The `Form_Load` event sets the drive and path to the drive and directory where the sample application is loaded, and specifies whether initialization information is stored in the registry or the `kvsdk.ini` file. Add the following code to the `Form_Load` event procedure:

    Private Sub Form_Load()
        Drive1.Drive = App.Path
        Dir1.Path = App.Path
        KEYview1.RegIniMode = 1
        KEYview1.RegIniName = "kvsdk.ini"
    End Sub

Command button Click event: The command button's Click event ends the application. Add the following code to the `Command1_Click` event procedure:

    Private Sub Command1_Click ()
        Unload Me
        End                ' Ends the application.
    End Sub

Drive list and directory list boxes Change events: To make the drive, directory, and file list boxes work together, add the following code to the `Drive1_Change` and `Dir1_Change` event procedures:

    Private Sub Drive1_Change ()
        Dir1.Path = Drive1.Drive        ' Update directory path.
    End Sub
    Private Sub Dir1_Change ()
        File1.Path = Dir1.Path        ' Update files.
    End Sub

File list box Double-click event: The `File1_DblClick` event procedure for the file list box displays the full path name of the selected file in the label control, and displays the picture itself in the image control. You need the following code:

    Private Sub File1_DblClick ()
        If Right(File1.Path, 1) <> "\" Then
            Label1.Caption = File1.Path & "\" & File1.FileName
        Else            ' If root directory
            Label1.Caption = File1.Path & File1.FileName
        End If
        nRet = KEYview1.Open(Label1.Caption)
    End Sub

Notice how the full path name is constructed:

- `File1.Path` returns the drive and directory path, `"\"` adds a backslash separator, and `File1.FileName` returns the file name.

- The `Right` function checks to see whether the path name is the root directory (`\`). If it is not, the full path name is assigned to the label's caption. If the path name is the root directory, the backslash is omitted.

- The `Open` method loads the file specified by the path name in the label caption.

© Copyright 2016-2020 Micro Focus or one of its affiliates | Send documentation feedback Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a mail client, and then send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm