hell of a problem using data types or adding an array
grasshopper
Posts: 438
Basically i am trying to take an array that a user can change by storing a baud rate in EEPROM. My problem is that if i add up the string that the user inputs i can seem to get it to be a correct value.
here is an example if a user inputs 9600
In the code the array Flash[noparse][[/noparse] 2 ] is where i would expect to find 9600 logicaly i thought adding RxString [noparse][[/noparse] 9 - 12] but it is not the case
9600 where the 9 is RxString[noparse][[/noparse] 9 ] and the 6 is RxString[noparse][[/noparse] 10 ] and the 0 is RxString [noparse][[/noparse] 11 ] and the 0 is RxString [noparse][[/noparse] 12 ]
My other foreseeable problem is that if a user inputs a number 19200 then the code will have to be modified
I could address this with an If statement but some help would be nice
here is an example if a user inputs 9600
FLASH[noparse][[/noparse] 2 ] := ((RxString[noparse][[/noparse] 9 ] * 1000) + (RxString[noparse][[/noparse] 10 ] * 100) + ( RxString[noparse][[/noparse] 11 ] * 10) + (RxString[noparse][[/noparse] 12 ]))
In the code the array Flash[noparse][[/noparse] 2 ] is where i would expect to find 9600 logicaly i thought adding RxString [noparse][[/noparse] 9 - 12] but it is not the case
9600 where the 9 is RxString[noparse][[/noparse] 9 ] and the 6 is RxString[noparse][[/noparse] 10 ] and the 0 is RxString [noparse][[/noparse] 11 ] and the 0 is RxString [noparse][[/noparse] 12 ]
My other foreseeable problem is that if a user inputs a number 19200 then the code will have to be modified
FLASH[noparse][[/noparse] 2 ] := ((RxString[noparse][[/noparse] 9 ] * 10000) + (RxString[noparse][[/noparse] 10 ] * 1000) + ( RxString[noparse][[/noparse] 11 ] * 100) + (RxString[noparse][[/noparse] 12 ] *10 ) + (RxString[noparse][[/noparse] 12 ] ))
I could address this with an If statement but some help would be nice
Comments
Did i explain it enough?
I really need help on this one
You've forgotten that the "Character" recieved will be in ASCII.· The ASCII character for "0" (zero) is 30.
}
PUB GetNum(InStrAddr) : Result | I, MyLen
· I := 0
· MyLen := STRSIZE(InStrAddr)
· repeat I from MyLen TO 0 STEP -1
··· Result := Result * 10
··· Result := Result + InStrAddr[noparse][[/noparse]I] - 30
· RETURN Result
Nice work thanks a million!!
This is what I was looking for .
the ASCII-Code for "0" zero is DECIMAL 48 and hexadecimal this is 30
a number without a leading "$" is interpreted as DECIMAL
so code has to be
best regards
Stefan
Post Edited (StefanL38) : 5/22/2008 9:29:47 PM GMT