Page 1 of 1

Confused a little

PostPosted: Thu Nov 24, 2016 8:26 am
by BRobinsonS
In an app for inventory control, I have a text field to enter Qty Sold and then an Extended amount is calculated i.e. QtySold * Price
However, the Math calculation doesn't execute if a period is entered first example .5 using code on Text Change Tab.
So I have attempted to check to see if first character is a period, if so add 0 to begin so math will execute.
But the routine keeps adding 0's each time I enter a new number. I believe the If clause should only act once.
What am I doing wrong? I tried StrIns with similar results.
Code below.

Code: Select all
SetVar "[firstchar]" ""
SubStr "[SoldQtyFld]" "1" "1" "[firstchar]"

If "[firstchar]" "=" "."
 SetVar "[SoldQtyFld]" "0[SoldQtyFld]"
EndIf

Math "[SoldQtyFld]*[CostFld]" "2" "[SalesExtend]"

Re: Confused a little

PostPosted: Thu Nov 24, 2016 12:15 pm
by Gaev
BRobinsonS:

Try...
Code: Select all
SetVar "[firstchar]" ""
SubStr "[SoldQtyFld]" "1" "1" "[firstchar]"

If "[firstchar]" "=" "!."
 SetVar "[SoldQtyFld]" "0[SoldQtyFld]"
EndIf

Math "[SoldQtyFld]*[CostFld]" "2" "[SalesExtend]"

... i.e. place an Exclamation Mark before the dot in the If command.

Re: Confused a little

PostPosted: Thu Nov 24, 2016 2:53 pm
by BRobinsonS
Thanks Gaev.
Saved me again.

It works as expected.
What did the ! mark do?
I understand it takes some calculation and makes them literal. ie. 1+ 1 = 1+1 using exclamation .

Re: Confused a little

PostPosted: Thu Nov 24, 2016 3:38 pm
by Gaev
BrianRobinsonS:

What did the ! mark do?

When you have ...
Code: Select all
If "[firstchar]" "=" "."

- the first parameter ... [firstchar] is a text value of "dot"
- the third parameter is interpreted as a number (0.0)

... so the two are not considered equal.

When you add an Exclamation Mark in front of a parameter value, NeoBook will not try and interpret it (i.e. it won't do math on it) ... so it treats it as a text value of "dot".

The lesson from this is ... When in doubt, try and insert an Exclamation Mark in front of it :)