PDA

View Full Version : Sending numbers



charleyshf
10-26-2011, 02:47 PM
Hello,,

The code I am working on is the following:


PUB testing
a := 0 '0-9
b := 60 '0-255
c := 255 '0-255
d := 255 '0-255'
e := 120 '0-255
f := 120 '0-255
g := 255 '0-255

outdata[0] := a
outdata[1] := b
outdata[2] := c
outdata[3] := d
outdata[4] := e
outdata[5] := f
outdata[6] := g

repeat i from 0 to 7(outdata)
PST.Dec(outdata[i])


This 'kind of ' works, however I was expecting the result of 060255255120120255 and instead I get an extra 0 at the end "0602552551201202550" . I could send each value one at a time with PST.Dec , but I would think there is a better way to do this, I am also using the PST object to display my results. Any ideas what I am doing wrong?

Ravenkallen
10-26-2011, 02:51 PM
You are sending a extra character it seems like. Try cutting the repeat line a little...

Repeat i from 0 to 6(Outdata)

See if that helps:)

Duane Degn
10-26-2011, 03:23 PM
Ravenkallen is correct.

You're sending an extra value to the PST. Your data is from 0 to 6 but your sending 0 to 7. I assume outdata[7] is either zero or undefined.

I don't understand "repeat i from 0 to 7(outdata)".

Are you missing a comment before "(outdata)"?

Duane

charleyshf
10-26-2011, 06:54 PM
Sorry, the line that reads repeat i from 0 to 7(outdata) should read repeat i from 0 to 7. Changing the 7 to 6 did the trick, can't believe I missed that one, Thank You!

charleyshf
10-26-2011, 08:48 PM
I ran into another problem, with the correction from above I get the proper responce, however I need the format of "0000000000000000000" , in other words if I want to send 90 in part of that, I need to actually send 090, it seems simple enough, but I am having a hard time trying to understand this, maybe I have to convert the responce to a string?

Thanks again

Duane Degn
10-26-2011, 08:59 PM
I couldn't find a simple example of zero padding so I wrote the code below.

I think this should work (I haven't tested it).



PUB Main | localIndex

repeat localIndex from 0 to 999
if localIndex < 100
pst.dec(0) ' was ("0")
if localIndex < 10
pst.dec(0) ' was ("0")
pst.dec(localIndex)



This should output a thee digit number with leading zeros when needed.

Duane

Edit: charleyshf's post made me realize I was using the dec method incorrectly. I fixed (I think) the code above.

charleyshf
10-27-2011, 05:52 PM
Thanks again,

Your example made me think about what I wanted the prop to do and this is working for me:


repeat y from 1 to 6
If outdata[y] < 100
SERIAL.Dec(0)
If outdata[y] < 10
SERIAL.Dec(0)
SERIAL.Dec(outdata[y])