Trying to calculate doesn't work.
Hitman
Posts: 5
Hi everybody,
Just a simpel guy from the Netherlands with a problem.
See listing below :
' {$STAMP BS2}
·sdata VAR Byte(11)
·dag VAR Byte
·dag2 VAR Byte
·rekendag VAR Byte
·main:
· SERIN 3,396,[noparse][[/noparse]STR sdata\10]
· DEBUG " ",STR sdata
· dag =·· sdata(0)
· dag2=·· sdata(1)
· rekendag =· sdata(0)+sdata(1)
· DEBUG " ",dag,dag2," ",DEC rekendag
· GOTO main:
·
A barcode scanner sends a date "12-12-2006" I see this on the debug screen, so far so good.
But, I extract "1" and "2" and then·I want to add those two so the result wil be "3".
On·the debug screen I see only "99" as a result of my calculation. What am I doing wrong? ?
I can't find a answer in the BS2 manual. And·I searched the internet already looking for a answer.
Please help me.
Emile Tempelaars.
The Netherlands.
Just a simpel guy from the Netherlands with a problem.
See listing below :
' {$STAMP BS2}
·sdata VAR Byte(11)
·dag VAR Byte
·dag2 VAR Byte
·rekendag VAR Byte
·main:
· SERIN 3,396,[noparse][[/noparse]STR sdata\10]
· DEBUG " ",STR sdata
· dag =·· sdata(0)
· dag2=·· sdata(1)
· rekendag =· sdata(0)+sdata(1)
· DEBUG " ",dag,dag2," ",DEC rekendag
· GOTO main:
·
A barcode scanner sends a date "12-12-2006" I see this on the debug screen, so far so good.
But, I extract "1" and "2" and then·I want to add those two so the result wil be "3".
On·the debug screen I see only "99" as a result of my calculation. What am I doing wrong? ?
I can't find a answer in the BS2 manual. And·I searched the internet already looking for a answer.
Please help me.
Emile Tempelaars.
The Netherlands.
Comments
What your getting, in the debug window,·is the ASCII representation of "1" & "2". To do math on these you will need to convert them back to 'real' numbers
ASCII 1 = 49
ASCII 2 = 50
Subtract 48 (decimal) from those two values and that should get you going:
For example in your code:
main:
SERIN 3,396,[noparse][[/noparse]STR sdata\10]
DEBUG " ",STR sdata
dag = sdata(0)
dag2= sdata(1)
rekendag = sdata(0) - 48
rekendag = rekendag + sdata(1)
recendag = rekendag - 48
DEBUG " ",dag,dag2," ",DEC rekendag
GOTO main:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
Thanks for the hint. You are right, how stupid of me.
Thanks again man.
I greet you and wish you a very happy an healthy 2007. (be careful with the fireworks)