• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to test for Cancel in ChooseFile

Community Expert ,
Mar 02, 2015 Mar 02, 2015

Copy link to clipboard

Copied

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");
    return;
  }
  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?

TOPICS
Scripting

Views

988

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Mar 02, 2015 Mar 02, 2015

Hi Klaus

you have to write the word "null"  :

if (inputFile == null)

then it should work

Votes

Translate

Translate
Community Expert ,
Mar 02, 2015 Mar 02, 2015

Copy link to clipboard

Copied

Looking into the FDK documentation confuses me even more.

Here a very first parameter *choice (aka selected file) is present

IntT F_ApiChooseFile(StringT *choice, StringT title, ... and the function result is the error code.

In the JSX the function result is the selected string or nul or ... - but how to distinguish?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 02, 2015 Mar 02, 2015

Copy link to clipboard

Copied

Hi Klaus

you have to write the word "null"  :

if (inputFile == null)

then it should work

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2015 Mar 03, 2015

Copy link to clipboard

Copied

Super -

What is this null? A constant? The editor knows it as a keyword - but what is the nature of this?

Step by step my project evolves - it seems to be at 2/3 of the coding now.

Again, thank You very much, Klaus

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 03, 2015 Mar 03, 2015

Copy link to clipboard

Copied

LATEST

"null" is a data type.

more infos you can get here :

English:

null - JavaScript | MDN

German:

null - JavaScript | MDN

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines