Group Abstract Group Abstract

Message Boards Message Boards

0
|
4K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

[?] Run a function using an If expression with "!=" ?

Posted 6 years ago

I have a function called processFile[fname_]...

The function works correctly when called as

processFile[fileName]

However, I want to call it thus:

fname = SystemDialogInput["FileOpen"];
If[fname != $Canceled, processFile[fname], "Error"]

When I select cancel, the If function returns Error, but when I select a file the If function returns

If["/Users/andy/Downloads/pqs.csv" != $Canceled, processFile[fname], "Error"]

What am I doing wrong?

Cheers Andy

POSTED BY: Andrew Burnett
2 Replies

Andy,

Use =!= (not same) instead of != because MMA knows they are not the same but does not know if they are “equal “. Read the documentation to get a more thorough description of the difference between same and equal.

Regards

Neil

POSTED BY: Neil Singer
Posted 6 years ago

Oh, that's interesting. Thanks very much. I will dig into how MMA handles equality in more depth.

Cheers Andy

POSTED BY: Andrew Burnett
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard