Subject: Persistent -Incorrect data type for operator or @function: Number Expected - error
It seems like you’re new around here, so before I take a stab at answering your question I’d like to suggest you have a look at this: http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/c458d490520b8baa852568890005f900?OpenDocument
Your question is more clearly expressed than many (and thank you for a meaningful subject line!) but there are some relevant details you might have included, such as:
Precisely when do you get the error message?
What values are in the fields C and B at the time?
What happens after you get the error message?
Is this a web application or a Notes client application (or both, or other)?
What is the formula for the computed field?
What are the default and input translation formulas for the editable field?
You say that field * a number works ( B * 2 ) but you don’t say that C * 2 works.
What is the formula with @ToNumber that didn’t work?
Not all of this information is relevant in this case, but it’s better to give more details whan you’re not sure what’s really important.
I’ll try to answer your question as best I can from the clues you offer. Here are some probably useful facts:
Computed fields are not buggy. This is a very basic type of functionality that’s been working since the very early days of Notes. You’ve misunderstood how they work.
A computed field formula, default or input translation formula does not need to assign its own field; your formula should not be of the form A := some value. That only worked by accident in this case. Just write an expression that returns the value you would like to store in the field.
If you do need to assign a field in a formula other than that field’s computed value, default or translation formula, use the FIELD keyword; otherwise you’re just creating a temporary variable that goes away when the formula ends.
The problem here is that one or both of the operands of your “*” operator is not a number – probably it’s a string or blank value. “” * 7 causes an error; so does “6” * 7.
If you use @ToNumber, use it on the operands, not on the result of the operation, because @ToNumber of an error is still an error. I.e. @ToNumber(B) * @ToNumber(C), not @ToNumber(B*C). However, even if the former formula works, you may still have another problem. Read on.
The datatype returned by a computed field formula, default formula or input translation formula overrides the field’s defined datatype. E.g. if the computed formula is @If(Status = “Draft”; “2”; “0”), then the value of the field will be the string “2” or “0”, not the number 2 or 0, even if the field is defined as a number field. While you can compensate for this by using @ToNumber to convert the value where you need to use the value, you potentially need to do this in many different places, including view column formulae. It’s easier to fix the one field formula.
If you are ever in any doubt as to the datatype or value of a field X in a formula, you can insert one or more statements such as the following at the beginning of the formula (replacing X with the field of interest):
@Prompt([ok]; “X”; @If(@IsError(X); “error”; @IsUnavailable(X); “no such field”; @IsText(X); “text”; @IsTime(x); “date/time”; @IsNumber(X); “number”; “other type”) + " <" + @Text(X) + “>”);
Keep this statement somewhere you can copy and paste it; I use something like this often for debugging. The resulting messagebox will tell you the datatype and value of X. E.g. if you get a value for C such as text <7> you know that is the cause of your problem.