PDA

View Full Version : STR function blues...



bearpawz
- 29th October 2004, 17:27
O.K., well I got my pulse count problems solved... Now the only problem is: Does anyone have a good routine on how to convert a number to a string? This is for odometer: so if say I have a mile count of 95,285 miles, I need to display "095285.0" on my display. (and before any one sugests it, using serout will not work: I have to store the string in an array...)

Mean while I'll keep searching the net.

bearpawz
- 29th October 2004, 18:36
Perfect example of RTFM here... but incase anyone else ever runs into the same problem, the key is the DIG Modefier. Here is the code I came up with:


For lcount = 0 to 9
MsgBuff[9 - Lcount] = OdCountL dig lcount + 48
Next


MsgBuff is an array where I store the VFD messages (kind of like a buffer)

Darrel Taylor
- 30th October 2004, 01:16
Hi bearpawz,

Along with RTFM, there's UTFM. Because, along with reading it, you have to Understand it. :)

The largest DIG you can use is 4. This is because the largest number you can have is 65535, which has only 5 digits. So, DIG 9 is out of the question.

Which begs the question, how are you storing mileage of 7 digits (6 + 1 decimal) "095285.0"? It's going to take more than just a word variable.

It can be done, but just not the way you've shown.

Best regards,
Darrel

bearpawz
- 30th October 2004, 02:10
Your absolutly right about that. One of the graces I have found with DIG is if the digit does not exest (like Dig 9), it returns a 0.. So so far everything looks fine until the word variably I have maxs out at 65535.

Since a 16 bit word is not big enough I have to store half in one word variable and the other half in another.




Some simple code:

OdCountL = OdCountL + 1 ' Increment Low Word Count
If OdCountL = 10000 then ' Roll Over at 9999 (999.9)
OdCountH = OdCountH + 1 ' Increment High Word Count
If OdCountH = 1000 Then ' Roll Over at 999 (999 + 999.9)
OdCountH = 0 ' Zero the High Word Counter
Endif
OdCOuntL = 0 ' Zero the low word counter
Endif

....

For lcount = 0 to 3
MsgBuff[9 - Lcount] = OdCountL dig lcount + 48
Next
For lcount = 0 to 2
MsgBuff[5 - Lcount] = OdCountH dig lcount + 48
Next