# ShowOpen
{: .no_toc }

Shows the Open dialog and returns the file that the user chose.

Syntax: *object*.**ShowOpen** ( ) **As Variant**

*object*
: *required* An object expression that evaluates to a **cDialog**.

Returns a **Variant**. When the user confirms the dialog, it holds the full path of the chosen file as a **String**. When the user cancels, it holds an empty string. With [**MultiSelect**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/MultiSelect.md) **True** and two or more files selected, it holds a 0-based array of **String** values, one full path for each file, as [below](#several-files) describes.

## Remarks

**ShowOpen** calls `GetOpenFileNameW` and takes its options from the properties of the object:

| Property | What **ShowOpen** passes |
|---|---|
| [**DialogTitle**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/DialogTitle.md) | `lpstrTitle`, the title |
| [**InitialDir**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/InitialDir.md) | `lpstrInitialDir`, the starting folder |
| [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) | `lpstrFile`, the text in the File name box when the dialog opens |
| [**Filter**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/Filter.md) | `lpstrFilter`, the file-type list |
| [**DefaultExt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/DefaultExt.md) | `lpstrDefExt`, the extension added to a name typed without one |
| [**MultiSelect**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/MultiSelect.md) | `OFN_ALLOWMULTISELECT` |
| [**OverwritePrompt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/OverwritePrompt.md) | `OFN_OVERWRITEPROMPT`, documented for Save As only |
| [**PathMustExist**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/PathMustExist.md) | `OFN_PATHMUSTEXIST` |
| [**FileMustExist**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileMustExist.md) | `OFN_FILEMUSTEXIST` |
| [**HideReadOnly**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/HideReadOnly.md) | `OFN_HIDEREADONLY` |
| [**ReadOnly**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ReadOnly.md) | `OFN_READONLY` |
| [**NoChangeDir**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/NoChangeDir.md) | `OFN_NOCHANGEDIR` |
| [**CreatePrompt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/CreatePrompt.md) | `OFN_CREATEPROMPT` |

A flag is set when its property is **True**. The method always sets `OFN_LONGNAMES`, `OFN_EXPLORER` and `OFN_ENABLESIZING`, selects the first pair of the filter, and has no owner window, hook or template. The [class page](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/index.md#settings-without-a-property) lists these settings.

An empty string means that the user cancelled, or that Windows reported a failure, such as a selected path that does not fit into the buffer, and no value tells which of the two happened. The buffer holds 260 characters, or 32,768 when [**MultiSelect**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/MultiSelect.md) is **True** or [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) is not empty. Neither case raises an error.

A confirmed **ShowOpen** that returns a **String** also stores it in [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md), and leaves [**InitialDir**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/InitialDir.md) as it was. A cancelled dialog changes neither. The next call therefore passes the previous path as the initial file name.

### Several files

With [**MultiSelect**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/MultiSelect.md) **True**, Windows returns the folder and then the name of each selected file in one buffer. **ShowOpen** joins the folder to each name with a backslash and returns the full paths as an array of **String** values, in the order in which the names stand in the File name box, and sets [**FileName**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) to an empty string. One selected file gives its full path as a **String**, as without **MultiSelect**. Test the result with **IsArray**, or call [**SelectFiles**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/SelectFiles.md), which returns a **Collection** in both cases.

## Example

This example shows the Open dialog for text files and prints the chosen path and name.

```tb check_build
Dim dlg As New cDialog
Dim path As String

dlg.DialogTitle = "Open a text file"
dlg.InitialDir = "C:\Reports"
dlg.SetCommonFilters

path = dlg.ShowOpen()
If Len(path) = 0 Then
    Debug.Print "Cancelled"
Else
    Debug.Print path
    Debug.Print dlg.GetFileName(path)
End If
```

## See Also

- [ShowSave](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowSave.md) method -- shows the Save As dialog
- [ShowBrowseForFolder](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowBrowseForFolder.md) method -- shows the Browse For Folder dialog
- [SelectAndOpenFile](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/SelectAndOpenFile.md) method -- shows this dialog and opens the file
- [SelectFiles](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/SelectFiles.md) method -- shows this dialog and returns the files as a collection
- [MultiSelect](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/MultiSelect.md) property -- lets the user select several files
- [FileName](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/FileName.md) property -- holds the path afterwards
- [cDialog](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/index.md) class -- overview
