4 Replies Latest reply on Mar 3, 2015 12:31 AM by Klaus Göbel

    How to test for Cancel in ChooseFile

    K.Daube Level 1

      Dear all,

      Again I'm stuck with some silly problem.

      When I cancel the ChooseFile dialogue, I want to bail out of the function GetTheFile. However, I have not found the appropriate test for this.

      The inputFile is reported to be null in the Cancel case:

      var prompt = "Select the formatted Citation file";
      GetTheFile ();
      function GetTheFile () {
        var inputFile = ChooseFile (prompt, GetDocPath (), "*.rtf", Constants.FV_ChooseSelect);
        if (inputFile == 0) {
          alert  ("No input - no processing");
        alert ("Further processing of the inputfile = " + inputFile);

      If I cancel, line 10 reports "Further processing of the inputfile = null".

      Testing in line 6 for the string "null" does not help either.

      The Scripting Guide says for this function:

      «The method returns 0 if the user clicked Open, Select, Use, or Save; a nonzero value if the user clicked Cancel or an error occurred»

      function GetDocPath () {
      // ----------------------------------------------- Get the document/book path
        var docFile, scrPath, lastBSlash;
        if (app.ActiveBook.ObjectValid()) {
          docFile = app.ActiveBook.Name;
        } else {
          docFile = app.ActiveDoc.Name;
        lastBSlash = docFile.lastIndexOf("\\");        // \ needs escaping
        scrPath = docFile.substring(0, lastBSlash);
        return scrPath;                                 // no final \ !
      } // --- end GetDocPath

      Testing in line 6 for !== 0 catches the valid input-file names (of course). So what is a valid test for the Cancelled function?