View Full Version : combining two vars

Chupa

08-06-2005, 04:18 PM

im trying to figure out how to combine two variables, and put a . between them. my code is like this:

var1 = united

var2 = states

i want var3 to be

var3 = var1"."var3

or

united.states

i cant figure this out for the life of me....

Paul Baker

08-06-2005, 11:27 PM

Hi Chupa,

I think your are confused about the basics of variable storage in a BS2. PBASIC variables can be a bit, 4 bits (nib), 8 bits (byte), or 16 bits (word). You haven't provided enough information to indicate whether you are trying to work with numbers or strings (1234 vs. "Hello"). Are you trying to concatonate the actually words "united" and "states", or is united defined to be a number (somewhere in your code appears something like "united = 234")?

Since a PBASIC variable permits a maximum of 16 bits and each letter in a string takes 8 bits, you could store a maximum of 2 letters in a variable (and you shouldn't do this anyways). To store a string variable you have to use an array of bytes which is group of bytes, each byte holding a letter. Refer to the Stamp User Manual for how to work with arrays. The problem with working with arrays, is the BS2 has a limited amount of varaible space (maximum of 26 bytes) and you will quickly run out of variable space when working with strings. There are ways around this if certain conditions are true, but I won't go into them unless it is clear this is what you are trying to do.

If you are trying to combine two numbers so that the first part is the integer value and the second part is the fractional part, the BS2 only works in integers. It doesn't understand how to work with fractions. Again there are ways around this if certain conditions are true, but I won't go into them unless it is clear this is what you are trying to do.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

·1+1=10

Post Edited (Paul Baker) : 8/6/2005 3:36:26 PM GMT

Chris Savage

08-06-2005, 11:44 PM

Hello,

·· About the only option left is to store the data in EEPROM in that order as you create the data.· This would involve using the WRITE and READ commands.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Chris Savage

Parallax Tech Support

csavage@parallax.com (mailto:csavage@parallax.com)

Chupa

08-07-2005, 12:19 AM

Humm, if the BS2 cant work in fractions Ill need to come up with a completley new idea. Thanks for the help!

Newzed

08-07-2005, 12:25 AM

The BS2 can work with fractions.· Take a look in the Help file about */ operators.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Sid Weaver

Do you have a Stamp Tester yet?

http://hometown.aol.com/newzed/index.html

·

Paul Baker

08-07-2005, 12:36 AM

There are ways around the fact the BS2 does not natively work in floating point,·frequently you can structure your programs to produce the identical results as if the BS2 does work with floating point. The first question you'll need to answer is: what is the maximum value (integer portion) that you will need to handle, the second is: what is the minimum value (fractional portion) you need to handle, third is: do you need to work with both negative and positive numbers, last is: what mathmatical operations will you be performing on the numbers, just add and subtract or multiply and divide as well?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

·1+1=10

Post Edited (Paul Baker) : 8/6/2005 4:40:36 PM GMT

Paul Baker

08-07-2005, 02:29 PM

I almost forgot, if you don't want the hassle of dealing with fixed point numbers (the alternative solution I mentioned), you can purchase the uM-FPU that Parallax sells for under $15. It is a floating point co-processor that will perform IEEE floating point operations for you.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

·1+1=10