Dialog SaveFile Error on Cancel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Gary Beene
    Member
    • May 2008
    • 20026

    Dialog SaveFile Error on Cancel

    On my PC, this code gives an error when I hit the Cancel button.

    But if I comment out the title$ = "Save" line, the failure does not occur. I don't even use the title$ variable (a left over from earlier code)! I was using it, and got the error. By elimination (including taking it out of the Dialog SaveFile statement) this was the line where the error seems to come from.

    Any ideas why I'm getting a failure?

    More data points:
    1. PB support tried the code and got no failure either way.
    2. I tried it on my wife's machine, and got no failure either way.
    3. I ran System File Check and it reported no problems.

    Code:
    #Compile Exe
    #Dim All
    #Include "Win32api.inc"
    Global hDlg As Dword
    Function PBMain() As Long
    
    Dim title$, filter$, flags&, filevar$
    
    filter$ = "BASIC" + $Nul + "*.bas" + $Nul
    title$ = "Save"
    
    flags& = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
    Display Savefile hDlg, 100, 100, "Save","c:\", filter$, "", "bas", flags& To filevar$
    
    End Function
    Last edited by Gary Beene; 25 Feb 2009, 11:59 AM.
  • Lee Bergeron
    Member
    • Oct 2000
    • 343

    #2
    I get no error also - what is the exact ERR message (#)

    Comment

    • Gary Beene
      Member
      • May 2008
      • 20026

      #3
      Here's what I got.

      Comment

      • Brian Chirgwin
        Member
        • Aug 2005
        • 350

        #4
        Win32API?

        Originally posted by Gary Beene View Post
        On my PC, this code gives an error when I hit the Cancel button.
        No error here.

        Try commenting out the #include "Win32api.inc". If it works maybe you have a corrupt include file.

        Comment

        • Gary Beene
          Member
          • May 2008
          • 20026

          #5
          I tried it without the win32api.inc reference and got the same error.

          I also re-installed PowerBASIC (twice) and still got the error.

          BTW, here's what I got when I clicked on the 'more detail' link on the top error message.



          I looked to see if my ntdll.dll file is somehow corrupt, but it was identical to the one on my wife's PC, where the error did not occur.

          Thanks for your responses. It's a weird error - having an unused variable cause a major failure of the exe.
          Last edited by Gary Beene; 25 Feb 2009, 01:37 PM.

          Comment

          • John Montenigro
            Member
            • Nov 2002
            • 1903

            #6
            Gary,

            I don't know why your code is working correctly on those other machines!?!

            Code:
            #Compile Exe
            #Dim All
            #Include "Win32api.inc"
            
            Global hDlg As Dword   [B][U]'Fine, you dim the variable here[/U][/B]
            
            Function PBMain() As Long
            
               Dim title$, filter$, flags&, filevar$
            
               filter$ = "BASIC" + $Nul + "*.bas" + $Nul
               title$ = "Save"
               flags& = %OFN_PathMustExist Or %OFN_Explorer Or %OFN_OverWritePrompt
            
            [B][U]   'BUT when you get here to use it, it hasn't been assigned a value!!![/U][/B]
               Display Savefile hDlg, 100, 100, "Save","c:\", filter$, "", "bas", flags& To filevar$
            
            End Function
            Well, I guess you're just relying on the default value to be 0, so maybe that's not a problem. But it's a loose end, and I wonder if the app will behave better when it's explicitly set?


            Hmm... I also don't see "%ofn_overwriteprompt" as a valid flag in the Help file...???




            Also, as mentioned in another curent thread, you may want to assign a value to the Display Savefile's start$ param, so that you can compare later for user-cancellation:

            Code:
               Display Savefile hDlg, 100, 100, "Save","c:\", filter$, start, "bas", flags& To filevar$
               if start = filevar$ then 
                  'user cancelled
               else
                  'you've got something
               end if
            Last edited by John Montenigro; 25 Feb 2009, 02:15 PM. Reason: Added note about: %ofn_overwriteprompt

            Comment

            • Gary Beene
              Member
              • May 2008
              • 20026

              #7
              Hi John,

              It has a 0 value at that point, which is appropriate for having the Desktop as its parent.

              Comment

              • Brian Chirgwin
                Member
                • Aug 2005
                • 350

                #8
                hDlg is optional you could try removing the parameter complete.

                If 0, the desktop is used as the parent. PB initializes numeric variables to 0. Is there a way to turn this off and use what random value exists in memory?

                Reasonable answer, but not convinced it is the problem.

                What OS are you using? It works here, I am on XP SP3. Are you using Vista, could Vista UAC be interfering with using the desktop as parent? Are you using and admin account. Doubt this is the issue, but can't think of anything else.

                Comment

                • John Montenigro
                  Member
                  • Nov 2002
                  • 1903

                  #9
                  What about removing that "%ofn_overwriteprompt" ??

                  I added to my post above that I don't see it as a valid flag in the Help file...???

                  Comment

                  • Steve Rossell
                    Member
                    • Mar 2005
                    • 1669

                    #10
                    The first thing you should do is try running it safe mode to see if this is being caused by another running processes, such as Anti-Virus.

                    Also you could have faulty memory chips, try running memtest86.exe (http://www.memtest.org/).

                    When you add extra variables or statements to your application you are changing the address of other statements and data in your compiled application and it could be that the new address is not being affected by memory corruption.
                    Sincerely,

                    Steve Rossell
                    PowerBASIC Staff

                    Comment

                    • Michael Mattias
                      Member
                      • Aug 1998
                      • 43447

                      #11
                      check the installed versions of COMDLG32.DLL
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment

                      • Gary Beene
                        Member
                        • May 2008
                        • 20026

                        #12
                        I took the cheating way out. I had a True Image ISO of my drive from about 2 months ago. I restored the system and the code works fine now.

                        I knew the code was working a month ago, and something changed. I didn't now what. I still don't know what.

                        So after trying several suggestions, I gave up and restored to a point that (I hoped) would work.

                        John - the %ofn_overwriteprompt is valid and in the .inc file, just not in Help. From MSDN: "In the Save As dialog box, display a message box if the selected file already exists. The user must confirm whether to overwrite the file. "

                        Michael - Doesn't the SFC check do this? Even if not, I did a byte comparison to the same file on another machine. No difference. I also checked the com*.dll files.

                        Brian - XP SP3, as was the 2nd machine.

                        Steve - Jeff at Support also suggested the Safe Mode. Somehow I didn't get around to trying it. I should have. Now I can't duplicate the problem but if it repeats, I'll try safe mode.

                        Thanks everyone for the help,
                        I'm assuming there was a corruption of some kind on my PC, I just don't know what. It didn't seem to be PB, since I re-installed it several times.

                        Comment

                        • Cliff Nichols
                          Member
                          • Aug 2006
                          • 3753

                          #13
                          Gary, Thank you for the post of the actual error message

                          I commented out #INCLUDE "Win32api.inc"
                          and amazingly it still worked with DISPLAY SAVEFILE statement

                          (which to me just verifies PB documentation of the DISPLAY SAVEFILE statement is built into PB now)

                          Being one that is used to ComDlg32.inc and using it for OpenFile and SaveFile this is kinda new to me.

                          Unfortunately I could not replicate the problem, but my best "Guesstimations" would assume one of the following avenues
                          1.) Your ComDlg32.inc has a invalid value? (Either mis declared, or capitalization or something else
                          2.) corrupt DLL (forgot which one would cause, but suspect ComDlg32.dll and Ntdll.dll just happened to catch the prior error)

                          Some other corruption that I can not think of at the moment...but worth looking into
                          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

                          • Chris Boss
                            Member
                            • Feb 1999
                            • 6478

                            #14
                            Just for the fun of it, try using 0 (zero) instead of the global variable hDlg.
                            Chris Boss
                            Computer Workshop
                            Developer of "EZGUI"
                            http://cwsof.com
                            http://twitter.com/EZGUIProGuy

                            Comment

                            • Gary Beene
                              Member
                              • May 2008
                              • 20026

                              #15
                              Whoops, duplicate. see next post.
                              Last edited by Gary Beene; 25 Feb 2009, 10:45 PM.

                              Comment

                              • Gary Beene
                                Member
                                • May 2008
                                • 20026

                                #16
                                hi Chris,

                                Yes, I tried that too. No change.

                                Here's another interesting point.

                                If I set either title$ = "", or just use "" in the Display SaveFile statement for title$, it works just fine - no error.

                                Any value for title$ other than "" gives an error.

                                But given that it works on a second machine regardless of the value of title$, the mystery isn't yet solved.

                                I passed this on to Support.

                                Comment

                                Working...
                                X