 1. ## Calculation Help

Hi All,

Simple calculation and have trouble when it is negative number

I have this and
1. Is there better way to calculate the Balance?
2. Do I have to change negative to positive number?

Code:
```'add number
a = 542
b = -211		'negative number
c = 186
d = 374

x = a+b+c+d		'Get total -- ok

'get the balance
'balance = a - b		'It is wrong result when the number is negative. Unknown negative number or not

if b < 0 then
'msgbox("b is less than 0 and ...")
'How to change to positive number?
balance = a + b		'Unknown negative number or not
else
balance = a - b		'Unknown negative number or not
end if
ui_msg_box("result","balance "+balance)```  Reply With Quote

2. ## Re: Calculation Help

if a,b,c,d are transactions, what is the beginning balance?

Zero?

What do you expect the balance to be?  Reply With Quote

3. ## Re: Calculation Help

Hi Al,

It is general subtract calculation, not typical "Balance" calculation.

what is the beginning balance? -- "A" Value
What do you expect the balance to be? --> a(*542) - b(*211) = 331.00

I want to write a code as xBal = a - b but when the "B" is negative number then trouble.

Thank you  Reply With Quote

4. ## Re: Calculation Help Originally Posted by johnkoh Hi Al,

It is general subtract calculation, not typical "Balance" calculation.

what is the beginning balance? -- "A" Value
What do you expect the balance to be? --> a(*542) - b(*211) = 331.00

I want to write a code as xBal = a - b but when the "B" is negative number then trouble.

Thank you
a-abs(b)  Reply With Quote

5. ## Re: Calculation Help

Thanks, Al  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•