取消
显示结果 
搜索替代 
您的意思是: 

What wrong w/ this formula node

The output is always -2,-2,-2... for the formula code below. I was expecting -2,-3.-4 for each iteration in a For loop.
 
The formula below is enclosed in a For loop, i is the loop counter and S=2.
 
I don't see why this order should matter Please confirm. The syntax help for formula node is crude.
 
int16 x;
if (s=1) x=-2;
 else
 x = -1*(s+i);
 
If I reverse the if else to then all is OK.
 
int16 x;
if (s>1) x = -1*(s+i);
else
(s=1) x=-2;
 
0 项奖励
1 条消息(共 10 条)
4,375 次查看
Is "if (s=1)" a valid equality test? I was thinking more along the lines of "if (s==1)", but then again I have never used a formula node.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 项奖励
2 条消息(共 10 条)
4,364 次查看
Yep, you beat me.  You are using asignment = instead of evaluation == .

Hope that this helps,
Bob Young

0 项奖励
3 条消息(共 10 条)
4,358 次查看
Your comparsion of 's=1' is incorrect. The single '=' is an assignment. The valid equal comparison is '==' (double equal sign). This is basic C syntax.
0 项奖励
4 条消息(共 10 条)
4,356 次查看
Thanks, the equality operator solved the issue. This must be quite as common as in writing C code. The LV help on Formula Nodes needs TLC, I'm using LV 7.1.
0 项奖励
5 条消息(共 10 条)
4,352 次查看
Well, to be fair it is not NI's strict responsibility to provide a C tutorial in the help for Formula Nodes.  I think that they are included so that it is easier to integrate already written code, and possibly to do things LV cannot do on its own (if there are indeed things C can do but LV cannot). 

I'm sure they'd much prefer to have extensive help on LV itself, and have you use LV to write your program, not C.

Just my 2 cents
0 项奖励
6 条消息(共 10 条)
4,343 次查看
I'm looking for consistency when going to help in LV. I'm doing LV also not C. A tutorial on C is not the idea, its far from it. This paste out of the help was a total waste the effort.
 
"The Formula Node syntax is summarized below using Backus-Naur Form (BNF notation). "
 
First who and what is Backus-Naur and just give me how the formula node syntax is typed. The big advantage is just that, i.e.  reading text not 20 or more arithmetic nodes.
 
Rich J
0 项奖励
7 条消息(共 10 条)
4,340 次查看
Oops, my apologies. It's been a long day.  For some reason "Formula Node" = "Code Interface Node" in my head.  I apologize for the oversight.  I agree with your points. Here's some info on Backus-Naur Form if you're interested.
0 项奖励
8 条消息(共 10 条)
4,327 次查看

This page from help helps somewhat, was found by searching formula, hope it helpshappy smiley

 

Precedence of Operators in Formula Nodes and Expression Nodes

The precedence of operators is as follows, from highest to lowest. Operators on the same line all have the same precedence.

** exponentiation
+, -, !, ~, ++, and –– unary plus, unary negation, logical not, bit complement, pre- and post-increment, pre- and post-decrement

++ and –– are not available in Expression Nodes.
*, /, % multiplication, division, modulus (remainder)
+ and addition and subtraction
>> and << arithmetic shift right and shift left
>, <, >=, and <= greater, less, greater or equal, and less or equal
!= and == inequality and equality
& bit and
^ bit exclusive or
| bit or
&& logical and
|| logical or
? : conditional evaluation
= op= assignment, shortcut operate and assign

op can be +, , *, /, >>, <<, &, ^, |, %, or **.

= op= is not available in Expression Nodes.
Note  In versions of LabVIEW earlier than 6.0, the ^ operator represented exponentiation. The ^ operator now represents the bitwise exclusive or (XOR) operation. The new operator for exponentiation is **, for example, x**y.

The assignment operator = is right associative (groups right to left), as is the exponentiation operator **. All other binary operators are left associative.

The numeric value of TRUE is 1, and FALSE is 0 for output. The logical value of 0 is FALSE, and any nonzero number is TRUE. The logical value of the conditional expression

<lexpr> ? <texpr>: <fexpr>

is <texpr> if the logical value of <lexpr> is TRUE and <fexpr> otherwise.

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 项奖励
9 条消息(共 10 条)
4,320 次查看
try

if (s==1) x;-2; note the double == for a conditional, otherwise you
set s=1.
Hmmm, you also need to change the else condition to either
-1*(-s+i) or just s-i to get the result you want.

TJW


On Wed, 31 May 2006 14:40:10 -0500 (CDT), richjoh <x@no.email> wrote:

>The output is always -2,-2,-2... for the formula code below. I was expecting -2,-3.-4 for each iteration in a For loop.
>&nbsp;
>The&nbsp;formula below&nbsp;is enclosed in a For loop, i is the loop counter and&nbsp;S=2.
>&nbsp;
>I don't see why this order should matter&nbsp;Please confirm. The syntax help for formula node is crude.
>&nbsp;
>int16 x;if (s=1) x=-2;&nbsp;else&nbsp;x = -1*(s+i);
>&nbsp;
>If I reverse the if else to then all is OK.
>&nbsp;
>
>int16 x;if (s&gt;1) x = -1*(s+i);
>else
>(s=1) x=-2;&nbsp;

0 项奖励
10 条消息(共 10 条)
4,309 次查看