Negative Numbers
kenwtn
Posts: 250
Hi Again All,
·
··········· I know when I pass a positive number everything works fine, but when I try to pass a negative number from Visual Basic Express to the Basic Stamp the number always turns positive. Can anyone help me out with how to pass negative numbers?
Code Line From VB Express:·
SerialPort1.WriteLine("++^++" & Cmd & vbCr & Format(CmdParm, "G"))
And Code Lines From BS2:
Command···· VAR·· BYTE··············· 'Command From Master
CmdParm···· VAR·· WORD··············· 'Command Parameter
SERIN 16,396, [noparse][[/noparse]WAIT("++^++"), DEC Command ,SDEC CmdParm]
·
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
·
··········· I know when I pass a positive number everything works fine, but when I try to pass a negative number from Visual Basic Express to the Basic Stamp the number always turns positive. Can anyone help me out with how to pass negative numbers?
Code Line From VB Express:·
SerialPort1.WriteLine("++^++" & Cmd & vbCr & Format(CmdParm, "G"))
And Code Lines From BS2:
Command···· VAR·· BYTE··············· 'Command From Master
CmdParm···· VAR·· WORD··············· 'Command Parameter
SERIN 16,396, [noparse][[/noparse]WAIT("++^++"), DEC Command ,SDEC CmdParm]
·
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
Comments
The SERIN ... SDEC <var> should work if the Format function supplies a "+" or "-" followed by a string of digits.
Post Edited (Mike Green) : 7/2/2008 1:36:47 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
Like I said, it should work. Do you have a dump of the text sent to the Stamp? That might show what's wrong.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
That is not strictly true, the "G" format is a general number without separators and should not be needed.
I am assuming your value is declared as an integer in VB and needs to be transmitted as a string
SerialPort1.WriteLine("++^++" & Cmd & vbCr & CmdParm.ToString)
Using SDEC3 to capture the value.
If you are then still having problems the cause could be the·way it is used·in the PBasic code.
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!
Harry
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Keep buying replacement parts and sooner or later you will get it RIGHT!