Source language: Translate to:

Confused a little

General questions about NeoBook

Moderator: Neosoft Support

Confused a little

Postby BRobinsonS » Thu Nov 24, 2016 8:26 am

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]"
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
BRobinsonS
 
Posts: 337
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada

Re: Confused a little

Postby Gaev » Thu Nov 24, 2016 12:15 pm

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.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Confused a little

Postby BRobinsonS » Thu Nov 24, 2016 2:53 pm

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 .
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
BRobinsonS
 
Posts: 337
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada

Re: Confused a little

Postby Gaev » Thu Nov 24, 2016 3:38 pm

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 :)
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 3 guests