Announcement

Collapse
No announcement yet.

PBWin.9 Display OpenFile SaveFile, Cancel action

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBWin.9 Display OpenFile SaveFile, Cancel action

    I'd like to use the new "Display OpenFile" or "Display SaveFile".
    Code:
    Display OpenFile hDlg,,, $MyCaption, InitialFolder$, $MyFilter, _
            StartFilename$, $MyDefaultExt, %MyFlagOpen To TempFilename$
    If Len(TempFileName$) > 0 Then
      'do something
    Else
      'nothing to do
    End If
    Using "Display OpenFile" or "Display SaveFile" with a valid starting filename:
    target filename seems updated to reflect the starting filename whatever button, 'OK' or 'Cancel', the user clicked on.

    This behavior doesn't reproduce GetOpenFileName or GetSaveFileName API function.
    How to know the user clicked 'Cancel' ? I guess 'Cancel' should return an empty string in target filename.

    Thanks for any comment.
    (forwarded to [email protected])
    Marc - France :-)

  • #2
    Just out of the back of my mind...(and BEWARE if you can see that )

    I have asked this question before, and the answer was either checking to see if it was blank....or creating a custom FileOpen

    Although really hazzy, cause I never had the time to track it down myself, I went with the blank.

    the bad part is if you set a default file, or someone else does, then it is no longer blank

    so where ever it is in POFFS or the archives is probably the better answer

    Let us know if you find it....Inquiring minds want to know
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

    Comment


    • #3
      Here's a snip from a program I recently updated:

      Code:
          DISPLAY OPENFILE hPgmDlg,,, "Select PADS ASCII file", g_sAppDir, _
                           "PADS ASCII File (*.asc)"+ CHR$(0)+"*.asc" + _
                           CHR$(0)+"All Files"+ CHR$(0)+"*.*"+ CHR$(0), _
                           "*.asc", "asc", _
                           %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR _
                            %OFN_LONGNAMES OR %OFN_EXPLORER TO g_PADSASCFile
      
      
          IF g_PADSASCFile = "*.asc" THEN  'user canceled
      When the user Cancels only the start$ parameter string, if any, is returned, without any added path. This is true even if you have selected a file, and then exited the dialog via "Cancel"
      Rick Angell

      Comment


      • #4
        target filename seems updated to reflect the starting filename whatever button, 'OK' or 'Cancel', the user clicked on.
        That is either a bug or a serious design flaw or some really poor documentation about detecting "no selection."

        Checking the filter value ( *.asc, *.txt etc. ) is silly... what if there are multiple flters and the user CHANGED the default filter BEFORE 'cancel' ? Which filter do you check? Does it change as the user changes it? Same with filename... what if user TYPES a filename in the box and the OFN_MUSTEXIST flag is specified, causing the function to not return at that point and they user then decides to CANCEL?

        I didn't install my 9x yesterday (that food, clothing and shelter thing got in the way) so I don't really know how its going to work under these conditions, but if I can't tell from the on-line doc then for sure the doc is tad weak.

        FWIW I *think* it should be documented and work as:
        filename$ {fully-qualified|unqualified} name of the file selected, or an empty string if the user canceled the dialog.
        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          I thought the API call actually returned a value to determine if canceled or not? I've been using FireFly's built-in function so long I forgot...I did see that the Display Browse is missing a line for folder$ in the online help, possibly in the main help as well, but I'm not at the programming PC at the moment.
          sigpic
          Mobile Solutions
          Sys Analyst and Development

          Comment


          • #6
            Since there was no such thing as DDT when I first did this, I have my own 'wrapper' function.

            My API doc is not handy but IIRC the underlying GetOpenFileName() function returns TRUE if a file is selected or FALSE if not.
            Code:
            ' OpenFileDialog with an explorer-style hook we use to center the window when it appears
            ' Same exact parameter string as used by 'OpenFileDialog'
            FUNCTION OpenFileDialogCentered (BYVAL hWnd AS DWORD, _   ' parent window
                                     BYVAL Caption AS STRING, _       ' caption
                                     Filespec AS STRING, _            ' filename
                                     BYVAL InitialDir AS STRING, _    ' start directory
                                     BYVAL Filter AS STRING, _        ' filename filter
                                     BYVAL DefExtension AS STRING, _  ' default extension
                                     Flags AS DWORD _                 ' flags
                                    ) AS LONG
            
                LOCAL Ofn            AS OPENFILENAME
                LOCAL szFile         AS ASCIIZ * %MAX_PATH
                LOCAL szFileTitle    AS ASCIIZ * %MAX_PATH
                LOCAL szInitialDir   AS ASCIIZ * %MAX_PATH
                LOCAL szTitle        AS ASCIIZ * %MAX_PATH
                LOCAL szDefExt       AS ASCIIZ * %MAX_EXT
            
                REPLACE "|" WITH CHR$(0) IN Filter
            
                IF LEN(InitialDir) = 0 THEN
                    InitialDir = CURDIR$
                END IF
            
                szInitialDir = InitialDir
                szFile       = Filespec
                szDefExt     = DefExtension
                szTitle      = Caption
            
                ofn.lStructSize      = SIZEOF(ofn)
                ofn.hWndOwner        = hWnd
                ofn.lpstrFilter      = STRPTR(Filter)
                ofn.nFilterIndex     = 1
                ofn.lpstrFile        = VARPTR(szFile)
                ofn.nMaxFile         = SIZEOF(szFile)
                ofn.lpstrFileTitle   = VARPTR(szFileTitle)
                ofn.nMaxFileTitle    = SIZEOF(szFileTitle)
                ofn.lpstrInitialDir  = VARPTR(szInitialDir)
                IF LEN(szTitle) THEN
                    ofn.lpstrTitle   = VARPTR(szTitle)
                END IF
                ofn.Flags            = Flags
                ' -------------------------------------------------------------------------------------
                ' Since callback (hook proc) is an explorer-style hook proc, we must set the OFN_ENABLEHOOK
                ' flag **and** must use the Explorer Style flag...and when using a hook proc you must
                ' set the OFN_ENABLESIZING flag or or the dialog will not be resizable.
                ' So make sure those flags are set...regardless of what got sent in....
                ' -------------------------------------------------------------------------------------
                ofn.flags            = ofn.flags OR %OFN_EXPLORER OR %OFN_ENABLEHOOK OR %OFN_ENABLESIZING
                '.. and set the callback procedure
                ofn.lpfnhook         = CODEPTR(OpenFileDialog_CenterProc)
                ofn.lpstrDefExt      = VARPTR(szDefExt)
            
                FUNCTION             = GetOpenFilename(ofn)
            
                Filespec             = szFile
                Flags                = ofn.Flags   ' << presumably this is returned only so user can test
                                                   ' if read-only was checked and is not checking the
                                                    ' ENABLEHOOK, ENABLESIZING or EXPLORER bits.
            
            END FUNCTION
            the above is the 'new' version. Here's its predecessor... with the return as I recalled it.

            Code:
            FUNCTION CallOpenSaveFileName (BYVAL hWnd AS LONG, BYVAL WhichSub AS LONG, OPTIONAL ReadOnly AS LONG)  AS STRING
               ' hWnd is the owner of the dialog
               ' WhichSub is %SUB_INPUT_FILE or %SUB_OUTPUT_FILE
               ' SUB_REPORT_FILE gets an output file with prompt for overwrite.
               ' Returns: Fully qualifed filename if user selects, or null string if he does not.
               ' Retains: Last directory searched for each file type
            
              STATIC AnyTrip AS LONG
              STATIC BeenHere() AS LONG          ' have we been here before for this purpose?
            
              STATIC OFN() AS OpenFileName       ' save the last choice
              STATIC Filter() AS STRING, Title() AS ASCIIZ * 48, SearchDir () AS ASCIIZ * %MAX_PATH
              STATIC FileTitle () AS ASCIIZ * %MAX_PATH  ' the name of the file
              LOCAL Stat AS LONG, wFullName AS ASCIIZ * %MAX_PATH
              LOCAL pFullName AS ASCIIZ PTR * %MAX_PATH
              LOCAL EC AS LONG
              LOCAL W AS STRING
              LOCAL AllowReadOnly AS LONG
            
            
              IF ISFALSE (AnyTrip) THEN
                 AnyTrip = %TRUE
                 REDIM OFN(%SUB_GETOPENSAVE_MAX), BeenHere(%SUB_GETOPENSAVE_MAX)
                 REDIM Title     (%SUB_GETOPENSAVE_MAX),_
                       SearchDir (%SUB_GETOPENSAVE_MAX),_
                       FileTitle (%SUB_GETOPENSAVE_MAX),_
                       Filter    (%SUB_GETOPENSAVE_MAX)
              END IF
            
            
              IF ISFALSE (BeenHere (WhichSub)) THEN
                 BeenHere (WhichSub) = %TRUE
                 OFN(WhichSub).lStructSize       = CDWD(SIZEOF(OFN(WhichSub)))
                 OFN(WhichSub).hInstance         = %NULL
                 OFN(WhichSub).lpstrCustomFilter = %NULL
                 OFN(WhichSub).nMaxCustFilter    = %NULL
                 OFN(WhichSub).nFilterIndex      = 1
                 OFN(WhichSub).lCustData         = 0
                 OFN(WhichSub).lpfnHook          = 0
                 OFN(WhichSub).lpTemplateName    = %NULL
                 OFN(WhichSub).lpstrDefExt       = %NULL
                 OFN(WhichSub).nFileOffset       = 0
                 OFN(WhichSub).nFileExtension    = %NULL
                 SearchDir (WhichSub) = CURDIR$
                 SELECT CASE WhichSub
                        CASE %SUB_INPUT_FILE
                             Title (WhichSub)           = "Select Input XML File"
                             OFN(WhichSub).LpStrTitle   = VARPTR (Title(WhichSub))
                             Filter(WhichSub)           = "XML (*.xml)" & $NUL & "*.xml" & $NUL & "All Files (*.*)" & $NUL & "*.*" & $NUL & $NUL
                             OFN(WhichSub).lpStrFilter  = STRPTR (Filter(WhichSub))
                             ' default flags:
                             OFN(WhichSub).Flags        =  %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_NOCHANGEDIR
                             ' 3.25.04 test readonly
                             ' if param sent and is true, offer option to open read only
                             ' do not include in here, make this "per trip"
                              'IF ISTRUE VARPTR (ReadOnly) THEN
                              '   IF ISTRUE ReadOnly THEN
                              '       OFN(WhichSub).Flags        =  OfN(WhichSub).flags OR
            
                             ' next line test 10/31/02 can we do multi-select without OFN_EXPLORER flag?
                             ' YES, we CAN
                            ' OFN(WhichSub).Flags  =  %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_NOCHANGEDIR OR %OFN_ALLOWMULTISELECT
                             ' next line test 10/31/02 what does OFN_EXPLORER do?
                             ' new dialog with option to create new folder.
                             ' BUt.. it appears OFN_EXPLORER flag is automatically put into the save if used for the OPen..
            
                            ' OFN(WhichSub).Flags  =  %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_NOCHANGEDIR OR %OFN_EXPLORER
                             OFN(WhichSub).LpStrDefExt   = %NULL
                             OFN(WhichSub).nFilterIndex  = 0&
                        CASE %SUB_OUTPUT_FILE
                             Title (WhichSub)            = "Select Tree Report File Name"
                             OFN(WhichSub).LpStrTitle    = VARPTR (Title(WhichSub))
                             Filter(WhichSub)            = "Text Files (*.txt)" & $NUL & "*.txt" & $NUL & "All Files (*.*)" & $NUL & "*.*" & $NUL & $NUL
                             OFN(WhichSub).lpstrFilter   = STRPTR (Filter(WhichSub))
                             OFN(WhichSub).Flags         = %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_OVERWRITEPROMPT OR %OFN_HIDEREADONLY OR %OFN_NOCHANGEDIR OR %OFN_EXPLORER
                             OFN(WhichSub).LpStrDefExt   = %NULL
                             OFN(WhichSub).nFilterIndex  = 0&
                   END SELECT
              END IF             ' if this is the first trip for this %SUB_xxxx
            
             ' else             ' we've done this browse before; restore the start directory to where we last were...
              OFN(WhichSub).LpStrInitialDir              = VARPTR(SearchDir(WhichSub))
            
              ' set the common stuff which does not vary...
              FileTitle(WhichSub)              = ""   ' no default filenamme
              OFN(WhichSub).LpStrFile          = VARPTR (FileTitle(WhichSub))
              OFN(WhichSub).nMaxFile           = SIZEOF (FileTitle(WhichSub))
              ' since the owner window may vary for the same sub across calls...
              OFN(WhichSub).hWndOwner         = hWnd
            
              ' Show the read-only box if input and AllowReadonly is true
            
            
              IF WhichSub = %SUB_INPUT_FILE  THEN
                 IF VARPTR(ReadOnly) THEN
                     IF ISTRUE (ReadOnly) THEN
                       AllowReadOnly = %TRUE
                     END IF
                 END IF
              END IF
              ' set the read only flag based on the value for this call
              IF ISTRUE AllowReadOnly THEN   '
                    ofn(WhichSub).flags =  OFN(WhichSub).flags AND NOT (%OFN_HIDEREADONLY)
              ELSE
                    ofn(WhichSub).Flags =  ofn(WhichSub).flags OR  %OFN_HIDEREADONLY
              END IF
            
              ' for testing the Explorer hookproc with output file 3/31/04
              IF WhichSub = %SUB_OUTPUT_FILE THEN
                  ' the read only variable is my "user" value I am going to use for my callback
                  ' NOTE: OFN_ENABLESIZING required when you use a hook proc or the dialog is not resizeable.
            
                  OFn(WhichSub).flags          = OFN(WhichSub).Flags OR %OFN_EXPLORER OR %OFN_ENABLEHOOK OR %OFN_ENABLESIZING
                  OFN(whichSub).lpfnhook       = CODEPTR (OFNExplorerHookProc)
                  OFN(whichSub).lCustData      = 12345&
            
             END IF
            
            
            
              ' call the API
              SELECT CASE WhichSub
                 CASE %SUB_INPUT_FILE
                      Stat = GetOpenFileName (OFN(WhichSub))
                 CASE %SUB_OUTPUT_FILE
                    Stat = GetSaveFileName (OFN(WhichSub))
              END SELECT
            
              IF ISTRUE (Stat) THEN
                 W                    = SPACE$(OFN(WhichSub).NMaxFile)
                 pFullName            = OFN(WhichSUb).LpStrFile
                 W                    = @pFullName
                 W                    = TRIM$(W, ANY CHR$(0, &h20))
                 ' set the initial search dir for the next time thru to equal this one
                 SearchDir (WhichSub) = LEFT$(W, INSTR(-1, W, "\"))
                 ' null out the file name for next call to provide consistent search behavior across 9x, NT and 2K:
                 FileTitle(WhichSub)  = ""
                 '
                 IF ISTRUE AllowReadOnly THEN   ' parameter passed, non-zero, input file
                      ReadOnly = (Ofn(whichSub).Flags AND %OFN_READONLY) = %OFN_READONLY  ' set to whatever was chosen
                     ' MSGBOX "Readonly=" & STR$( (Ofn(whichSub).Flags AND %OFN_READONLY) = %OFN_READONLY)
                 END IF
                 FUNCTION = W
              ELSE
                 LOCAL eCD AS DWORD
                 eCD                  = CommDlgExtendedError
                 IF ECD <> 0 THEN
                    MSGBOX "GetOpen/SaveFileName failed on error#" & STR$(eCD), %MB_APPLMODAL OR %MB_ICONINFORMATION, "Yikes!!!
                 END IF
                 FUNCTION             = ""
              END IF
            
            END FUNCTION
            MCM
            Last edited by Michael Mattias; 20 Sep 2008, 12:09 PM.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Originally posted by MCM:
              Checking the filter value ( *.asc, *.txt etc. ) is silly... what if there are multiple flters and the user CHANGED the default filter BEFORE 'cancel' ?
              Not necessarily silly, not the filter either, nor is it documented as has been noted. You check the return filename against the start$ which is a single file name, albeit it can have a wildcard character. That string does not change, even if the filter selection is changed.

              start$
              A string which specifies the starting file name to be used as the initial file selection. This may be disabled by passing a nul, zero-length string ("").
              It is not necessarily sleepyhead proof either since one could enter a path/filespec and get the same back. So it is best to use with a wildcard in the filename and no path ... since an actual selection would not contain the wildcard and would include a path.

              Would it be better to also return a code we can check? Obviously, yes.
              Last edited by Richard Angell; 22 Sep 2008, 08:50 AM.
              Rick Angell

              Comment


              • #8
                You check the return filename against the start$ which is a single file name, albeit it can have a wildcard character.
                So what if it's the same? If I canceled it's not the same as though I accepted the value, is it?
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  In my testing, Cancel returns the start$, always, even if you had selected a file from the list first. Maybe Bob can shed some light on this? Bob?
                  Last edited by Richard Angell; 22 Sep 2008, 08:49 AM.
                  Rick Angell

                  Comment


                  • #10
                    FWIW, Display Browse returns an empty string when you cancel, just as one would expect.

                    Comment


                    • #11
                      This is another good example of having the ability to use a PB command in function format rather than statement format. There are several cases in PB where a function variation would be prefered over the statement implementation. I guess that, to me, using a function format is intuitively more satisfying than the overly verbose statement formats. Nonetheless, I rather have it in statement form rather than nothing at all.
                      Paul Squires
                      FireFly Visual Designer (for PowerBASIC Windows 10+)
                      Version 3 now available.
                      http://www.planetsquires.com

                      Comment


                      • #12
                        Thanks for your comments.
                        As long Display OpenFile / SaveFile do not change their behavior with 'cancel'action, I 'll keep my own 'wrapper' like Michael.
                        Marc - France :-)

                        Comment


                        • #13
                          Ms

                          All the DISPLAY statements are already PBWin9 compiler wrappers.

                          You can easily just take a different approach to check the result, checking the returned string instead of a return value flag. You can easily center on your screen, window or dialog. You should not need to include COMDLG32.INC or roll your own from now on, plus the help file page is always there for a refresher. The COMDLG32 equates are now part and parcel of PB Win's BASIC and the compiler. The code below demonstrates a commented version and then a typical, statement with a check for cancel and if so abort test. Obviously, one can test, if canceled, give the user the opportunity to try again, or just a quick MSGBOX ("?") to notify they cancelled.

                          Code:
                          #COMPILE EXE
                          #DIM ALL
                          FUNCTION PBMAIN () AS LONG
                              LOCAL File2Use$, start$,folder$
                              ' start$ usually will use a wild card, BUT ALSO be sure
                              ' start$ DOES NOT include a path, typical usage AND
                              ' the path is specified in the folder$ variable position in the call.
                              ' The actual path is returned if the "OPEN" button is selected, this then
                              ' provides additional difference in cases where start$ might specify a
                              ' an exact file name, for example: "calendar.bas"
                              folder$ = CURDIR$   'or use a quoted string in the DISPLAY OPENFILE call
                              start$ = "*.bas"    'or use a quoted string in the DISPLAY OPENFILE call
                              
                              DISPLAY OPENFILE ,,, "Wrapped! Centered!", folder$, _
                                              CHR$("BASIC", 0, "*.BAS;*.INC;*.BAK", 0),start$, "BAS", _
                                               %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR  _
                                               %OFN_EXPLORER TO File2Use$
                          
                              IF File2Use$ = start$ THEN  'check for CANCEL
                                  ? "User Canceled ! We know this because" + $CRLF + _
                                    "File2Use$ = "& File2Use$ & " = start$ = "&   start$
                              ELSE
                                  ? File2Use$ & " was returned. Note that it includes" + $CRLF + _
                                    "with a path AND it does not = start$ = "& start$
                              END IF
                          '----------------------------------------------------------------------------------
                          ' here is a more likely call in a program to a known directory structure
                          ' if the user cancels, you just exit the function or maybe add some code
                          ' to allow the user to try, try, again or quit!
                          ' STILL ONE STATEMENT, ONE TEST, NO ADDITIONAL WRAPPERS NEEDED
                          '----------------------------------------------------------------------------------
                              
                              DISPLAY OPENFILE ,,, "Wrapped! Centered!", "\PBWin90\Samples\DDT\Calendar", _
                                              CHR$("BASIC", 0, "*.BAS;*.INC;*.BAK", 0),"calendar.bas", "BAS", _
                                               %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR  _
                                               %OFN_EXPLORER TO File2Use$
                              IF File2Use$ = "calendar.bas" THEN EXIT FUNCTION  'nothing to do
                              ' Try again and OPEN calendar.bas
                              ? File2Use$ & " was returned. Note that it includes" + $CRLF + _
                                    "with a path so it does not just = start$ = calendar.bas"
                          END FUNCTION
                          Rick Angell

                          Comment


                          • #14
                            Rick,

                            Thanks for the code to test with.

                            It would appear that if the user clicks on a filename but then clicks on Cancel, the program does not detect the cancellation.

                            I'll be playing with this some more after dinner...

                            Comment


                            • #15
                              Filter$ does not appear to work.
                              Code:
                                
                              Sub y_Save_As
                                 common_locals   
                                 Local Folder, Filter, Strt, deftxt, filevar As String
                                 Local flags As Long
                              '
                                 Row = 20
                                 Col = 20
                                 Folder$ = ""
                                 Filter$ = "*.SWL" & Chr$(0)'$Nul         
                                 Strt$ = Trim$(prm.Current_File_Name)
                                 Deftxt$ = "SWL"
                                 
                                 Display SaveFile hdlg, Col, Row, $Title & " - Save File As:", Folder$, Filter$, Strt$, DefTxt$, Flags To Filevar$
                                  ? Filevar$
                              End Sub
                              The above shows ALL files in the folder, not just *.SWL. I've tried any number of variations (Well obviously not the number that works. {arrgh}

                              ==============================================
                              "The truth is more important than the facts."
                              Frank Lloyd Wright (1868-1959)
                              ==============================================
                              It's a pretty day. I hope you enjoy it.

                              Gösta

                              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                              Comment


                              • #16
                                When I use OpenFile I test for the return filevar$ to be "". If "" then the user cancelled. Does that not work for you?


                                Code:
                                'Compilable Example:
                                'NOTE: see the commented lines for several ways in which to handle file display filters
                                #Compile Exe
                                #Dim All
                                Global hDlg As Dword
                                Function PBMain() As Long
                                   Local hParent as Dword, title$, folder$, filter$, start$, defaultext$, flags&, filevar$, countvar&
                                   hParent = hDlg          'if not parent, use 0 or %hWnd_Desktop
                                   title$ = "Open File"     'if "", then "Open" is used
                                   folder$ = "c:\"          'if "", then current directory is used
                                   filter$ = Chr$("PowerBASIC", 0, "*.bas", 0)    'same as:  "BASIC" + $Nul + "*.bas" + $Nul
                                      'filter$ consists of pairs of $Nul terminated description/pattern values
                                      'filter$ example:    Chr$("All Files", 0, "*.*", 0)
                                      'filter$ example:    Chr$("BASIC", 0, "*.bas;*.inc;*.bak", 0)
                                      'filter$ example:    Chr$("Bitmap Files", 0, "*.bmp", 0, "All Files", 0, "*.*", 0)
                                   start$ = "myfile.txt"               'starting filename
                                   defaultext$ = "bas"
                                   flags& = %OFN_Explorer Or %OFN_FileMustExist Or %OFN_HideReadOnly
                                   Display OpenFile hParent, 100, 100, title$, folder$, filter$, start$, _
                                                     defaultext$, flags& To filevar$, countvar&
                                   'filevar$ contains returned name of file selected, "" if no file is selected
                                   'countvar$ contains number of files selected
                                   If Len(filevar$) Then
                                      MsgBox filevar$
                                   Else
                                      MsgBox "No file selected!"    'ESC or Cancel
                                   End If
                                End Function

                                Comment


                                • #17
                                  Gösta,

                                  filter$
                                  A string expression containing pairs of null-terminated filter strings.
                                  The first string in each pair describes the filter, and the second the filter pattern.

                                  In your code the 'second string' is missing = null = all files! Try this..
                                  Code:
                                      Filter$ = "SWL Type" + CHR$(0) + "*.SWL" + CHR$(0)
                                  Rgds, Dave

                                  Comment


                                  • #18
                                    Or the alternative (my favorite):
                                    Code:
                                    Filter$ = CHR$("SWL Type",0,"*.SWL",0)
                                    James

                                    Comment


                                    • #19
                                      Originally posted by Dave Biggs View Post
                                      Gösta,

                                      filter$
                                      A string expression containing pairs of null-terminated filter strings.
                                      The first string in each pair describes the filter, and the second the filter pattern.

                                      In your code the 'second string' is missing = null = all files! Try this..
                                      Code:
                                          Filter$ = "SWL Type" + CHR$(0) + "*.SWL" + CHR$(0)
                                      Thank you Dave. That was it. Just another in a long of me not reading the docs correctly. Geez, sometimes I wonder how I made it out of Mrs. Makin's 4th grade class.

                                      Gary, I hadn't gotten far enough along to handle the return yet.

                                      jc, I will try your favorite. After all I play no favorites and bet on the favorites all the time.

                                      Boy this forum is great. Have a problem, post here, go to bed, have sweet dreams, get up and dreams come true - problem solved. Ain't life grand!!?

                                      ===================================
                                      "The only difference between me
                                      and a madman is that I'm not mad."
                                      Salvador Dali (1904-1989)
                                      ===================================
                                      It's a pretty day. I hope you enjoy it.

                                      Gösta

                                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                      Comment

                                      Working...
                                      X