combining variables
Thric
Posts: 109
Hi,
I'm trying to create a program that finds a single characther in a txt file that·is located on a SD card and then stores that value into an array. However when a certain charcheter is reached (like a comma) then I need to combine all my previous values so that I end up with a number. Heres an example:
buf[noparse][[/noparse]1]:=5, buf[noparse][[/noparse]2]:=8, and buf[noparse][[/noparse]3]:=","
then I need to some how store buf[noparse][[/noparse]1] and buf[noparse][[/noparse]2] into a single variable to equal 58.
·Sorry if its a little confusing, its hard for me to explain something I don't know how to do .
Thanks
I'm trying to create a program that finds a single characther in a txt file that·is located on a SD card and then stores that value into an array. However when a certain charcheter is reached (like a comma) then I need to combine all my previous values so that I end up with a number. Heres an example:
buf[noparse][[/noparse]1]:=5, buf[noparse][[/noparse]2]:=8, and buf[noparse][[/noparse]3]:=","
then I need to some how store buf[noparse][[/noparse]1] and buf[noparse][[/noparse]2] into a single variable to equal 58.
·Sorry if its a little confusing, its hard for me to explain something I don't know how to do .
Thanks
Comments
All you Prop pros out there correct me if I'm wrong on this, but I believe you can do something like this:
x := (buf * 10) + buf
MG117
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
BS2: $49
SX48 Protoboard: $10
Propeller Protoboard: Priceless
www.apple.com
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.jameco.com
· will this work with the following example?
buf[noparse][[/noparse]1]:=2·· buf[noparse][[/noparse]2]:=3 ·buf[noparse][[/noparse]3]:=7 ·buf[noparse][[/noparse]4]:="."· buf[noparse][[/noparse]5]:=9 ·buf[noparse][[/noparse]6]:=","
So the outcome will have to be 237.9
Post Edited (Thric) : 6/27/2010 3:17:21 AM GMT
John Abshier
do you want the numbersmfor calculations inside the prop or are you just displaying them?
In the commandset of the SPIN-interpreter you can only calculate with INTEGERs.
For floating point you would have to use floatingpoint math-object
If you want the numbers only to DISPLAY with really really NO calculations you can do this
buf[noparse][[/noparse] 1 ]:=2 buf[noparse][[/noparse] 2 ]:=3 buf[noparse][[/noparse] 3 ]:=7 buf[noparse][[/noparse] 4 ]:="." buf[noparse][[/noparse] 5 ]:=9 buf[noparse][[/noparse] 6 ]:=","
defining a second array of bytes
remember as soon as you want to do any kind of calculations you have to convert the characters into a real integer
how this works depends on the format how your numbers are stored on the SD-card
the above example will work if the numbers are stored as ASCII-codes characters
so next step for you is to post an answer with more information of how the values are stored and what you want to to with the values
best regards
Stefan
The informations is stored on the sd card in a txt file as ASCII. What I want to do is take each character into a a buffer till a comma is found then combine those numbers and do some further calculations with them. the object I'm using for my sd card is the Fat 16 routines by john Twomey (http://obex.parallax.com/objects/402/) if this helps at all.
To use it you will pass a pointer to the first character of the string you want to convert, for example:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA