User Tools

Site Tools


filedialog_return_chosen_file_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== FILEDIALOG (return chosen file) ====== Previous pageReturn to chapter overviewNext page

FILEDIALOG( [title] ,file [,extensions] [,flag] )

blk2blue.jpg

FILEDIALOG Displays Windows standard file choice dialogs to allow the user to choose a file.
title A string constant or variable containing the title to place on the dialog. If omitted, Windows supplies a default.
file The label of the string variable to receive the selected filename(s).
extensions A string constant or variable containing the available file extension selections for the “List Files of Type” drop list. If omitted, the default is all files (*.*).
flag An integer constant or variable containing a bitmap to indicate the type of file action to perform.

The FILEDIALOG procedure displays Windows standard file choice dialogs and returns the file chosen by the user in the file parameter. Any existing value in the file parameter sets the default file choice presented to the user in the file choice dialog.

FILEDIALOG displays either the standard Open… dialog or the standard Save… dialog. By default, on the Open… dialog, the user is warned if the file they choose does not exist and the file is not opened. On the Save… dialog, the user is warned if the file does exist and the file is not saved.

The extensions parameter string must contain a description followed by the file mask. All elements in the string must be delimited by the vertical bar (|) character. For example, the extensions string:

'All Files | *.* | Clarion Source | *.CLW;*.INC;*.EQU;*.INT | Clarion Templates|*.TPL;*.TPW'

defines three selections for the “List Files of Type” drop list. The first extension listed in the extensions string is the default. Multiple extensions are separated by a semicolon (;) character.

The flag parameter is a bitmap that indicates the type of file action to perform (see EQUATES.CLW for symbolic constants). For bit number:

0 If zero (0000b), the Open… dialog displays.
1 If one (0001b), the Save… dialog displays.
2 If two (0010b), saves and restores the current directory path.
4 If four (0100b), doesn't report errors if the file does exist on Save… or does not exist on Open….
8 If eight (1000b), returns multiple selections when the user selects multiple files. When using long filename dialog, it returns a vertical bar () delimited string of filenames (with the full path on the first selection returned, unless a single file is selected, where the path and file is returned on a single selection). The string is space-delimited when using short filename dialog. Not valid when used with File:Save or File:Directory.
16 If sixteen (10000b), uses long filename dialog in 32-bit programs.
32 If thirty-two (100000b), displays a directory select dialog for selecting a directory path.
64 If sixty-four (1000000b), and the specified and typed file name does not exist, the dialog displays a prompt to create a new file with the given name. If the user chooses to create the file, the FILEDIALOG function completes and returns the typed file name; otherwise the dialog remains open. This flag can't be combined with the FILE:Directory flag.
128 If one-hundred twenty eight (10000000b), and the specified file name is typed without an extension, the default extension is appended. The default extension is the one used in the first mask for the first filter pair. If there are meta-characters (* or ?) in the default extension, the flag is ignored. The flag is also ignored if either or both of the FILE:Multi and FILE:Directory flags are used. To type in the file name without an extension if the FILE:AddExtension is specified, the file name must be enclosed in quotes (i.e., “myfile”). Due to a Windows restriction, if the default extension is longer than 3 characters, only the first 3 characters are appending to the file name.

The following is a comprehensive sample of these flags simplified to equates (see EQUATES.CLW for the complete list):

FILE:Save EQUATE(1)
FILE:KeepDir EQUATE(2)
FILE:NoError EQUATE(4)
FILE:Multi EQUATE(8)
FILE:LongName EQUATE(10H)
FILE:Directory EQUATE(20H)
FILE:CreatePrompt EQUATE(40H)
FILE:AddExtension EQUATE(80H)

FILEDIALOG returns zero (0) if the user pressed the Cancel button, or one (1) if the user pressed the Ok button on the file choice dialog. If the user changes directories using the file dialog, your application's current directory also changes (unless you set FILE:KeepDir). This is a feature of the Windows operating system. If you do not want users to change your application's current directory but do want them to be able look in other directories, either save the current directory with the PATH() procedure before calling FILEDIALOG then restore it with the SETPATH() statement, or set FILE:KeepDir.

Return Data Type: BOOL

Example:

ViewTextFile PROCEDURE

ViewQue QUEUE                   !LIST control display queue

        STRING(255)

       END

FileName   STRING(64),STATIC    !Filename variable

ViewFile  FILE,DRIVER('ASCII'),NAME(FileName),PRE(Vew)

Record     RECORD

           STRING(255)

          END

         END

MDIChild1 WINDOW('View Text File'),AT(0,0,320,200),MDI,SYSTEM,HVSCROLL

          LIST,AT(0,0,320,200),USE(?L1),FROM(ViewQue),HVSCROLL

         END

CODE

IF NOT FILEDIALOG('Choose File to View',FileName,'Text|*.TXT|Source|*.CLW',FILE:LongName)

 RETURN                        !Return if no file chosen

END

OPEN(ViewFile)                 !Open the file

IF ERRORCODE() THEN RETURN END!aborting on any error

SET(ViewFile)                  !Start at top of file

LOOP

 NEXT(ViewFile)                !Reading each line of text

 IF ERRORCODE() THEN BREAK END !Break loop at end of file

 ViewQue = Vew:Record          !Assign text to queue

 ADD(ViewQue)                  !and add a queue entry

END

CLOSE(ViewFile)                !Close the file

OPEN(MDIChild1)                !and open the window

ACCEPT                         !Allow the user to read the text and

END                            !break out of ACCEPT loop only from

                               !system menu close option

FREE(ViewQue)                  !Free the queue memory

RETURN                         !and return to caller

!

!This example shows using FILEDIALOG for multi-file selection:

SelectFiles   PROCEDURE(SelectFileQueue DFQ)

Found       CSTRING(10000),AUTO

Path        CSTRING(File:MaxFilePath),AUTO

Separator   STRING(1),AUTO

Pos         UNSIGNED,AUTO

NameStart   UNSIGNED,AUTO

 CODE

 Found=SELF.DefaultFile

 IF FILEDIALOG('Pick 1 or more files',Found, |

 'All Files | *.* | Clarion Source | *.CLW;*.INC;*.EQU;*.INT|Clarion Templates|*.TPL;*.TPW',|

  FILE:KeepDir+FILE:Multi+FILE:LongName)

   Separator='|'

   Pos=INSTRING(Separator,Found,1,1)

   IF Pos                                 !Multi-Selected files

     ASSERT(Pos > 1)

     Path = CHOOSE(Found[Pos-1] <;> '\', Found[1 : Pos-1]&amp;'\', Found[1 : Pos-1])

     LOOP

       NameStart = Pos+1

       Pos = INSTRING(Separator,Found,1,NameStart)

       IF ~Pos THEN Pos=LEN(Found)+1.

       DFQ.Name = Path&amp;Found[NameStart : Pos-1]

       ADD(DFQ)

     WHILE Pos<;=LEN(Found)

   ELSE

     DFQ.Name=Found                                !Single file only selected

     ADD(DFQ)

   END

 END

!

!This example shows using FILEDIALOG for multi-file selection:

FILEDIALOG('Test', FileName, 'Text files|*.txt|All files|*.*', |

           FILE:LongName + FILE:NoError + FILE:AddExtension)

!If the user types AAA and pressed the Open button, the returned file

!name is '<;current directory>\AAA.txt'; if the user typed “AAA”,

!result is '<;current directory>\AAA'

See Also:

FILEDIALOGA

SETPATH

SHORTPATH

LONGPATH

DIRECTORY

GETFONT

SETFONT

PROP:FontDialogHook

filedialog_return_chosen_file_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1