String lenght
VladaPUB
Posts: 139
I have a problem receiving different lenght of EIB EIS5 value (temperature).
Sometimes it is 7.00 (4 caracters) and sometime 10.00 (5 caracters)
How to make it always 5 characterm in fact how to add ZERO (0) in front in case that i have less than 5 caracters ????
Sometimes it is 7.00 (4 caracters) and sometime 10.00 (5 caracters)
How to make it always 5 characterm in fact how to add ZERO (0) in front in case that i have less than 5 caracters ????
0
Comments
and i need to send it to another device like here
Can you show me that on this example how should look ?
would you really do it like that?
Wouldn't it be ALOT nicer to use FORMAT()?
like this:
this *should* format the string so that it is always 5 characters long, and has a precision of 2 decimals right of the decimal point...
disclaimer:
the format bit it psuedo code, but you get my point
I think this would work as well, just changing cTemperature[5] as it would drop the added zero if 5 characters are returned and keep if if only 4 characters are returned.
I obviously don't always go wtih the shortest, cleanest method and generally write so I can easily tell what's going on in th furture.
I?m a big fan of FORMAT also and prefer it over string manipulation but in this case the FORMAT command won?t work as intended (even disregarding the ?pseudo? code that?s not formatted correctly ) since cTemperature is already ASCII.
If you want to use the FORMAT command with vining?s CHAR cTemperature[5] then one way to do it is like this:
SEND_STRING 0, "FORMAT('%05.2f',ATOF(cTemperature))"
If you were starting with FLOAT fTemperature then you would do it like this:
SEND_STRING 0, "FORMAT('%05.2f',fTemp)"
Both of the above examples will return a 2 digit precision after the decimal point, force a 5 character minimum width, and pad with leading 0s if need be.
If 5 characters are returned in DATA.TEST then the ?0? that you are appending won?t be dropped, the last character will be dropped instead. So if DATA.TEXT = ?12.34? then the result of ??0?,DATA.TEXT? will be ?012.3?
To each their own as far as programming style, whatever works best for the individual. However, I think the FORMAT command is extremely powerful and worth learning.
Every time I'm start feeling smart I realize how stupid I still am. Damm!
There is no shifting going on assuming you?re talking about watching a buffer something like this:
cBuffer = ?cBuffer,DATA.TEXT?
DATA.TEXT keeps getting appended to the end of cBuffer and if cBuffer gets full then any remaining bytes of DATA.TEXT gets lost. (If Netlinx didn?t keep us safe in the sandbox then the remaining bytes would get written to the next chunk of memory which could be disastrous as you could possibly write over the program itself.)
Maybe you?re thinking about GET_BUFFER_CHAR? In that instance position 1 of the buffer gets extracted and all the remaining bytes shift to the left by one.
Been there done that more times than I?d care to admit. But that?s what makes it so much fun. There is always room to learn and grow.
you're right. It was late and i didn't have my trusty Netlinx Studio at hand for help :P
but it sending
How to reformat it to remove first 0 ?