Announcement

Collapse
No announcement yet.

Display SaveFile question

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

  • Display SaveFile question

    Code:
    '  Display SaveFile [hParent], [xpos], [ypos], title$,     folder$, filter$, start$, DefExt$, flags To FileName$
       Display SaveFile , , , "Choose a Folder and File Name", CurDir$, "", fn$, "Test", flag To FN$
        ?fn$ & $CrLf & Str$(Flag),, FuncName$
    The above displays and returns the choice (FileName$) as expected. However how do I know if the user clicks the Cancel Button or the Save button? What it the user changes his mind and doesn't want to Save (Cancels)?
    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/

  • #2
    Since this is the 1st I have seen "Display" and not used it yet, I suspect it in turn calls "OpenFileDialog" in the api???

    If so then 2 questions hold true and I hope you find your answer
    1.) Returning results = ?????? (not documented, and not documented if there is a return value)
    2.) How to tell what was returned? (Cancel?? FileName??? or what???, since till now my only experience with "OpenFileDialog" is to not offer a default name, and if still blank on return then the user must have cancelled????)

    Interesting questions, and hoping someone has viable answers
    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
      Hi Gösta,

      This thread contains some useful information, particularly Richard Angell's post #13.

      Regards,

      Pete.

      Comment


      • #4
        Thanks Pete. Probably never woul hve found the answer myself. Unusual way to check. Here's a quick sample answer:

        Code:
        '  Display SaveFile [hParent], [xpos], [ypos],     title$,     folder$, filter$,  start$, DefExt$, flags To FileName$
           Display SaveFile , , , "Choose a Folder and File Name",   "C:\Temp",      "",     [B]fn$[/B],  "Test", flag To [B]FN1$[/B]
         
          'check for cancel operation
           If [B]fn1$ = fn$[/B] Then   
              ? "Cancelled"
                Exit Sub
           End If
         
           ? "Got here, so Not cancelled"
        ======================================
        Poetry is the deification of reality.
        Edith Sitwell
        ======================================
        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


        • #5
          Does that work if I change the selected file name, and THEN cancel?

          The bottom line is still as I suggested in the linked post: when CANCEL is selected, the function should return a null string. (as in, "I didn't select nuttin'")

          If it doesn't, then it's either poorly-designed or buggily implemented.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Originally posted by Michael Mattias View Post
            Does that work if I change the selected file name, and THEN cancel?
            Yes, or at least it did on the one time I tried it.


            The bottom line is still as I suggested in the linked post: when CANCEL is selected, the function should return a null string. (as in, "I didn't select nuttin'")

            If it doesn't, then it's either poorly-designed or buggily implemented.

            MCM
            Far be it from me to disagree with the Grand Poohbah of PB.

            However the Cancel can be detected, so that's where the money is. It would have been nice if it had been explained in the docs, though.

            ================================
            If I could drop dead right now,
            I'd be the happiest man alive.
            Samuel Goldwyn
            ================================
            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


            • #7
              Ok I give. (I don't use shortcuts like fn$), but quick compile and wonder why I get an error of fn$ is not defined?

              Code:
              #COMPILE EXE
              #DIM ALL
              
              FUNCTION PBMAIN () AS LONG
                  '  Display SaveFile [hParent], [xpos], [ypos],     title$,     folder$, filter$,  start$, DefExt$, flags To FileName$
                 DISPLAY SAVEFILE , , , "Choose a Folder and File Name",   "C:\Temp",      "",     fn$,  "Test", flag TO FN1$
              
                'check for cancel operation
                 IF fn1$ = fn$ THEN
                    ? "Cancelled"
                      EXIT SUB
                 END IF
              
                 ? "Got here, so Not cancelled"
              
              END FUNCTION
              what CNDS (as MCM has coined) am I committing????
              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


              • #8
                As the error message says, you get an error because fn$ is not defined. If you use #DIM ALL, you have to declare the variables before you use them.
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  >If you use #DIM ALL

                  "If" you use '#DIM ALL?'

                  "IF?"

                  Doesn't everyone?
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Originally posted by Cliff Nichols View Post
                    Ok I give. (I don't use shortcuts like fn$)
                    Pretty cool. I'd find it very difficult to work without shortcuts like strings (fn$). Yet another technique I'll have to learn someday.

                    what CNDS (as MCM has coined) am I committing????
                    What you did was drop what was supposed to be an illustrative snippet into working code. I probably should have made the example more clear. My bad.

                    =============================================
                    "The difference between fiction and reality?
                    Fiction has to make sense."
                    Tom Clancy
                    =============================================
                    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


                    • #11
                      Code:
                      FUNCTION PBMAIN () AS LONG 
                       
                        LOCAL hParent,xpos,ypos, flags,countvar AS LONG
                        LOCAL title,folder,filter,start,defaultexts,filevar AS STRING
                       
                        DISPLAY SAVEFILE hParent&, xpos&, ypos&, title$, folder$, filter$, _
                        start$, defaultexts$, flags& TO filevar$ ,countvar&
                        IF countvar = 0 THEN ? "Cancelled or closed"
                       
                      END FUNCTION

                      Comment


                      • #12
                        >TO filevar$ ,countvar&

                        Countvar?

                        You must have a different help file. Mine from Pb/Win 9.0.0:
                        DISPLAY SAVEFILE statement
                        Purpose
                        Display a SaveFile selection dialog to return user choices.

                        Syntax
                        DISPLAY SAVEFILE [hParent], [xpos], [ypos], title$, folder$, filter$, _
                        start$, defext$, flags TO filename$
                        Ain't got no "countvar&" in this version. However, that certainly ends the problem. Quite neatly, too.

                        I should probably test it before I go much further. Assuming that works, I guess I have another bug to report.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Gosta
                          What you did was drop what was supposed to be an illustrative snippet into working code. I probably should have made the example more clear. My bad.
                          Not a prob, but I just missed what would be pseudo-code, would not just drop into a compilable and "Just Work"

                          José brought up a goood point with
                          As the error message says, you get an error because fn$ is not defined. If you use #DIM ALL, you have to declare the variables before you use them.
                          and MCM with the counter-punch, but since I am one for declaring everything myself, and not PbDefaults, then you both have a point.

                          1st problem. - PB by default adds the following if I select "Generic Pb Program"
                          #COMPILE EXE
                          #DIM ALL

                          FUNCTION PBMAIN () AS LONG



                          END FUNCTION
                          which has the #DIM ALL, but for some reason does not include the Win32Api.Inc?????

                          2nd problem - Comment out #DIM ALL and only variable not defined is "flag" (could be a koinky-dink that it is a long and not shortcutted?).....hmmmm yep after test with changing "flag" to "flag&" it compiles

                          now maybe its just me, or the way I read the docs....but shortcut and declare can NOT be mixed and matched (which apparently I was, and did not know it)

                          3rd Problem (since I am one for declaring everything)
                          when I tried to declare, I got "Type Id (?%&!#$) not allowed"

                          (Gotta laugh at the point of (?%&!#$) cause that is what I was doing at the time it happened

                          The problem was I was attempting to declare the "Shortcut" as in
                          Code:
                               LOCAL fn$ AS STRING
                               LOCAL fn1$ AS STRING
                               local flag& as long
                          which come to find out has to be without the shortcut

                          all boils down to programming style, but since I do not use the "Shortcuts" and Pb by default forces the declare, I ran into a "What In the FUBAR" am I doing wrong??? (and the only thing different was taking shortcuts)

                          at least now I know and "Knowing is Half the battle"

                          (maybe fodder for a Gary post??)



                          Anyways, Gost is reallllllLLLLLLllll close to having a solution to my age ole problem of detecting if cancelled was used. (I tricked it twice but have not been able to replicate)
                          Code:
                          #COMPILE EXE
                          #DIM ALL
                          
                          FUNCTION PBMAIN () AS LONG
                          '     local fn$ as string
                          '     local fn1$ as string
                          '     local flag& as long
                               LOCAL fn AS STRING
                               LOCAL fn1 AS STRING
                               LOCAL flag AS LONG
                               Fn$ = "Default File"
                              '  Display SaveFile [hParent], [xpos], [ypos],     title$,     folder$, filter$,  start$, DefExt$, flags To FileName$
                             DISPLAY SAVEFILE , , , "Choose a Folder and File Name",   "C:\Temp",      "",     fn$,  "Test", flag& TO FN1$
                          
                            'check for cancel operation
                             IF fn1$ = fn$ THEN
                                ? "Fn$ = " + Fn$ + $CR _
                               + "Fn1$ = " + Fn1$ + $CR _
                               + "Cancelled"
                                  EXIT FUNCTION
                             END IF
                          
                             ? "Fn$ = " + Fn$ + $CR _
                               + "Fn1$ = " + Fn1$ + $CR _
                               + "Got here, so Not cancelled"
                          
                          END FUNCTION
                          The only thing I dont get is how
                          Code:
                             DISPLAY SAVEFILE , , , "Choose a Folder and File Name",   "C:\Temp",      "",     fn$,  "Test", flag& TO FN1$
                          can work fine without tripping a compile problem? (I always thought anything you look for a reply from would have to be passed in parenthesis???
                          aka
                          Code:
                             DISPLAY SAVEFILE (, , , "Choose a Folder and File Name",   "C:\Temp",      "",     fn$,  "Test", flag&) TO FN1$
                          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


                          • #14
                            See options for CALL in help file.
                            The one that got me was the first time I saw a FUNCTION name return a value instead of the usual FUNCTION=1
                            Code:
                            FUNCTION PBMAIN () AS LONG
                              LOCAL result AS LONG
                              Test TO result 'See CALL in help file
                            END FUNCTION
                             
                            FUNCTION TEST() AS LONG
                              TEST = 1 'or FUNCTION=1
                            END FUNCTION

                            Comment


                            • #15
                              The only thing I dont get is how
                              Code:
                              DISPLAY SAVEFILE , , , "Choose a Folder and File Name", "C:\Temp", "", fn$, "Test", flag& TO FN1$
                              can work fine without tripping a compile problem? (I always thought anything you look for a reply from would have to be passed in parenthesis???
                              Perhaps you're expecting the Statement to behave like a Function?
                              Rgds, Dave

                              Comment


                              • #16
                                test drive this

                                Here's a complete example, providing a Function that returns "" if the user cancelled.

                                After it passes inspection, I'll post its tattered remnants on the Source Code forum for future searches...

                                -jhm


                                Code:
                                'DisplayOpen_Cancel.bas   by jhm
                                
                                #Compile Exe
                                #Dim All
                                
                                Function PBMain () As Long
                                   Local hParent, lXpos, lYpos, lFlags As Long
                                   Local sTitle, sFolder, sFilter, sInitFN, sDefExt, sRet, m As String
                                   
                                   sTitle   = "Choose a Folder and File Name to Open"
                                   sFolder  = "c:\tools"   'the folder you want initially displayed (trailing \ or not, doesn't matter)
                                   sFilter  = Chr$("Text", 0, "*.txt", 0) & Chr$("Config", 0, "*.cfg;*.ini", 0)  'choices for FileType drop-box
                                   sInitFN  = "Text1.txt"  'a name you want initially shown and selected
                                   sDefExt  = "*.txt"      'the extension you want appended if user omits one
                                      
                                
                                   'set the first 3 params to -1 if you don't care what their values are.
                                   sRet = Display_Openfile(-1,-1,-1, sTitle, sFolder, sFilter, sInitFN, sDefExt, lFlags)
                                
                                   'test it with some numeric values...
                                   'sRet = Display_Openfile(-1,300,50, sTitle, sFolder, sFilter, sInitFN, sDefExt, lFlags)
                                
                                   If sRet = "" Then
                                      m = "Cancel"
                                      'do the stuff you'd do when user cancels the selection
                                   Else
                                      m = sRet
                                      'do the stuff you'd do when user has selected a file
                                   End If
                                   
                                   MsgBox m,,"Dialog ended with: "
                                   '...and they lived happily ever after...
                                   
                                End Function
                                
                                
                                Function Display_Openfile(ByVal hParent As Long, _
                                                          ByVal xpos    As Long, _
                                                          ByVal ypos    As Long, _
                                                          ByVal title   As String, _
                                                          ByVal folder  As String, _
                                                          ByVal filter  As String, _
                                                          ByVal start   As String, _
                                                          ByVal sDefExt As String, _
                                                          ByVal flags   As Long)       As String
                                
                                   Local tmp As String
                                
                                   'by using -1 as an indicator, we allow caller to pass 0, if truly wants dialog in the corner.
                                   'yes, we sacrifice the -1,-1 window position, but is that really a loss? then use some other value...
                                   If hParent = -1 Then
                                      If     xpos =  -1 And ypos =  -1 Then
                                         Display Openfile ,,,     title, folder, filter, start, sDefExt, flags To tmp
                                
                                      ElseIf xpos =  -1 And ypos <> -1 Then
                                         Display Openfile ,,ypos, title, folder, filter, start, sDefExt, flags To tmp
                                
                                      ElseIf xpos <> -1 And ypos =  -1 Then
                                         Display Openfile ,xpos,, title, folder, filter, start, sDefExt, flags To tmp
                                
                                      ElseIf xpos <> -1 And ypos <> -1 Then
                                         Display Openfile ,xpos,ypos, title, folder, filter, start, sDefExt, flags To tmp
                                
                                      End If
                                   Else
                                
                                      If     xpos =  -1 And ypos =  -1 Then
                                         Display Openfile hParent,,,     title, folder, filter, start, sDefExt, flags To tmp
                                
                                      ElseIf xpos =  -1 And ypos <> -1 Then
                                         Display Openfile hParent,,ypos, title, folder, filter, start, sDefExt, flags To tmp
                                
                                      ElseIf xpos <> -1 And ypos =  -1 Then
                                         Display Openfile hParent,xpos,, title, folder, filter, start, sDefExt, flags To tmp
                                
                                      ElseIf xpos <> -1 And ypos <> -1 Then
                                         Display Openfile hParent,xpos,ypos, title, folder, filter, start, sDefExt, flags To tmp
                                
                                      End If
                                   End If
                                
                                   If start = tmp Then  'user cancelled
                                      Function = ""
                                   Else                 'user selected something
                                      Function = tmp
                                   End If
                                End Function

                                Comment

                                Working...
                                X