2

I have a problem with this error message appearing when the button is used: "Incorrect data type for operator or @Function: Number Expected"

Everything works fine - it just pops up the error message when "Needs Checking" is selected

Code:

@Command( [EditDocument]; "1" ); FIELD STAT := @Prompt([OkCancelList]; "Select and Action"; "Checking Status?"; "STAT"; "Needs Checking" : "Needs Amending" : "Checked" ); @If(STAT="Needs Checking";@SetField("USER";@Name([CN];@UserName)) & @SetField("REF";@Unique) & @Command([FileSave]) & @Command( [EditDocument]; "0" ) & @Command([Folder];"Checking";"1") & @Command([CloseWindow]); @Command([FileSave]) & @Command( [EditDocument] ; "0" ) & @Command([Folder];"";"1") & @Command([CloseWindow]))

Thanks :)

ClaaziX
  • 113
  • 1
  • 8

1 Answers1

3

The & is a logical operator and not for concatenating of commands. That way you do something like

ResultOfCommand1 & ResultOfCommand2 & ResultOfCommand3

This is a comparison and returns true or false. If one of the results is not numerical, then you get the error.

Use "@Do" to concatenate more than one command in your if:

@Command( [EditDocument]; "1" ); 
FIELD STAT := @Prompt([OkCancelList]; "Select and Action"; "Checking Status?"; 
  "STAT"; "Needs Checking" : "Needs Amending" : "Checked" ); 
@If( STAT="Needs Checking";
    @Do( @SetField("USER";@Name([CN];@UserName));
      @SetField("REF";@Unique);
      @Command([FileSave]);
      @Command( [EditDocument]; "0" );
      @Command([Folder];"Checking";"1");
      @Command([CloseWindow]) ); 
    @Do( @Command([FileSave]);
      @Command( [EditDocument] ; "0" );
      @Command([Folder];"";"1");
      @Command([CloseWindow])) )

But this is still "bad code" as it contains a lot of duplicate code. I would do it like this (still not best code, but better):

@Command( [EditDocument]; "1" );
FIELD STAT := @Prompt([OkCancelList]; "Select and Action"; "Checking Status?"; 
  "STAT"; "Needs Checking" : "Needs Amending" : "Checked" ); 
@If( STAT = "Needs Checking"; 
    @Do( @SetField("USER";@Name([CN];@UserName));
      @SetField("REF";@Unique);
      @Set( _folderName; "Checking" )
    ); "" );
@If( @Command( [FileSave] ); "" ; @Return( "" ) );
@Command([Folder];_folderName;"1");
FIELD SaveOptions := "0";
@Command([CloseWindow]);

e.g.: I check if the document can be saved (Field validation, Continue = Fals in QuerySave... If not: Stop processing.

Then I just put the things in the @If, that are different for both cases.

Setting EditMode to "0" is not necessary as you immediately close the document after. To prohibit a "Do you want to save your changes" I set SaveOptions to "0" (this will not be saved in document). The foldername is in a variable, so that @Command( [Folder] ; ... ) can use it.

Tode
  • 11,795
  • 18
  • 34
  • brilliant! thanks so much Torsten, this make a lot of sense. Didn't know of the @Do function, that certianly makes things tidier! The reason I needed the If not function was because if the STAT field is "Needs Checking" I want it to go into the Folder named Checking....but If it is not I want the user to be able to choose the folder. I should be able to work this out though - thanks for your help! – ClaaziX Jul 16 '14 at 15:25
  • 1
    My second suggestion does exactly that: it sets the variable "_folderName" in the @If... in the else case it is NOT set, then the `@Command([folder] ; _folderName; "1" )` will do the same as `@Command([folder] ; ""; "1" )` – Tode Jul 17 '14 at 06:03