From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

FileSelectPopup always returns 0

CVI 2012, Win XP, Main Thread, on two different computers:

 

FileSelectPopup, with all the correct parameters passed, always returns 0, whether the operator selects a new file name, an existing file name and selects replace, or cancels.  FileSelectPopup should return a 1 or a 2 for the the first two cases, and 0 only for the cancel.  For new or existing file name, even though it returns 0, it returns a good path string.

 

This seems like some kind of new behaviour.  This chunk of code has worked properly before, looking for a 1 or 2, and worked in several different apps.

 

Any idea what is going on?

0 Kudos
Message 1 of 7
(3,234 Views)

Are you using a watch expression and stepping through your code to see the value be returned as zero? It is possible the value is being overwritten to zero elsewhere in the code that would make it seem like it eliciting this behavior.

Ian M.
National Instruments
0 Kudos
Message 2 of 7
(3,210 Views)

I stepped through the code -- that's how I found out it returns 0 always.

 

I worked around this by nulling the path string, and looking at the first character after return, even when the call returns 0.

 

err is local to this function:

 

   if ( err = FileSelectPopup (SupportDirName, SensorParamsFilename, ".txt",
              "Save Coefficients to File...", VAL_SAVE_BUTTON,
            1, 1, 1, 0, SnsrParamsFilePath) IS_LESS_THAN 0)
    {
    sprintf(tempString, "FileSelectPopup Error:  %s\n", GetUILErrorString(err) );
    SysLogEntry(tempString);
    break;
    }
   
   SysLogEntry("Save Params File: FileSelectPopup return value %i\n", err);

0 Kudos
Message 3 of 7
(3,196 Views)

The error is a result of setting err and then comparing it from within the if statement. If you first set err = FileSelectPopup then check if(err < 0) then you should see err will be nonzero. In my quick test I was able to recreate your issue but if you change the code as I mentioned it will work correctly.

Ian M.
National Instruments
0 Kudos
Message 4 of 7
(3,172 Views)

Seems pretty standard to embed a function call with return value inside a conditional.  I don't think I've seen an issue like this before.  But if you've recreated this, I'll take your word for it.  I suppose adding parens around the function call, so it is evaluated first, would solve it too.

 

 if ( ( err = FileSelectPopup (SupportDirName, SensorParamsFilename, ".txt",
              "Save Coefficients to File...", VAL_SAVE_BUTTON,
            1, 1, 1, 0, SnsrParamsFilePath) ) IS_LESS_THAN 0)

 

Thanks for your help...

0 Kudos
Message 5 of 7
(3,160 Views)

The precedence of the less-than operator is higher than that of the assignment operator. This is why you must always include the parentheses, otherwise you're assigning the boolean result of the less-than comparison to your variable, not the result of the function call.

0 Kudos
Message 6 of 7
(3,142 Views)

Or possibly insert 2 calls in the if clause?

 

 if (err = FileSelectPopup (SupportDirName, SensorParamsFilename, ".txt", "Save Coefficients to File...", VAL_SAVE_BUTTON, 1, 1, 1, 0, SnsrParamsFilePath), err IS_LESS_THAN 0) {
  ....
}

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 7
(3,129 Views)