comp • gb.form.dialog • dialog • openfile

Dialog.OpenFile (gb.form.dialog)

Static Function OpenFile ( [ Multi As Boolean ] ) As Boolean

Calls the file standard Dialog to get the name of a file to open.

  • If Multi is FALSE (the default), then the user can only select one file, and the path of the selected file is returned in the Path property.

  • If Multi is TRUE, then the user can select several files, and the path of the selected files is returned as a string array in the Paths property.

This method returns TRUE if the user clicked on the Cancel button, and FALSE if the user clicked on the OK button.

Examples

Dialog.Title = "Choose a file"
Dialog.Filter = ["*.txt", "Text Files", "*", "All files"]
Dialog.Path = "."
If Dialog.OpenFile() Then
  Return ' User pressed Cancel -
Endif

This example shows how you can select multiple files with the OpenFile dialog. By setting the Dialog.Path when the application starts the first time the dialog is opened it will show the users home directory.

Public Sub Form_Open()
  Dialog.Path = User.Home
End

Public Sub ButtonOpenMultiple_Click()
  Dim imageFile As String
  Dialog.Filter = ["*.png", "Portable Network Graphics"]
  If Dialog.OpenFile(True) Then Return
  For Each imageFile In Dialog.Paths
    Print imageFile
  Next
Catch
  Message.Info(Error.Text)
End