News:

;) This forum is the property of Proton software developers

Main Menu

Dword to String converter

Started by JackB, Dec 11, 2024, 09:30 PM

Previous topic - Next topic

JackB

Hello everyone

When looking for a Dword to String converter I've read about the compiler 8 manual page:399
then I took sometime to read about different function from Positron and came up with
this way to convert a Dword value to a string, value tested range from 0~4294967295.
the code listed is free to use as is enjoy.

Device = 18F14K22       
Declare Xtal = 64
Config_Start
  FOSC = IRC    ; Internal RC oscillator
  PLLEN = On    ; PLL is under software control
  MCLRE = OFF
Config_End
OSCCON = $70    ;for 64Mhz   ;p:17
Declare Hserial_Baud = 9600
Declare HRSOut1_Pin = PORTB.7

MAIN:
While PORTA.3 = 1: Wend             ' Button Press
While PORTA.3 = 0: Wend             ' Start on release
DelayMS 20                          ' Tactile switch Bounce delay

Dim ABC As Dword                    ' ABC Dword
Dim PDigit As Byte                  ' Dig / Digit
Dim ABCString As String = ""        ' ABC String
Dim I As Byte                       ' Extract digit position
ABC = 4294967295                    ' Dword Value

For I = 9 To 0 Step -1              ' Start Loop to 0
    PDigit = Dig ABC, I             ' Extract digit's position
    Inc PDigit, 48                  ' Convert to ASCII (0~9)
    ABCString = ABCString + PDigit  ' String concatenation
Next

HRSOutLn  ABCString                 ' Send to Terminal
GoTo MAIN

trastikata

:)
sMyString = Str$(Dec dMyDword)

JackB

Thx,
for the ASCII Decimal converter


JackB


Hello,

I just found the example code in Positron manual

(Strn String1 = Str$(Dec Wrd1) ' Convert the Integer to a String)
work even better with less code.

Thank you again for your help.


top204

With a String variable, there is no need to use the Strn command, just use the String's name:

String1 = Str$(Dec Wrd1)

The Strn command was added for the old, standard 14-bit core devices many years ago, before I added real String variables to the compiler for 18F devices, then for the enhanced 14-bit core devices when they came out, because they both have a linear RAM mechanism for indirect access to it. So the Strn command uses a byte array as well, and adds a terminating null to the end of it.

JackB

Many thanks Les,

You took the time to explain clearly the 'under the hood' process for theses function

this is a great way to help novice like me to understand.

If I may ask is there an new version of the compiler book in the future, or this is the last edition.

Thanks again for the great work you do.

RGV250

QuoteIf I may ask is there an new version of the compiler book in the future, or this is the last edition.
Do you mean the manual, if so it is constantly updated when new features are added or a typo etc is discovered.

Regards,
Bob

JackB


The 'Positron8 BASIC Compiler Manual'
since there's no revision date printed on the manual.
like on page 51 found this where [Index] should be  [bIndex]
'bMyArray[Index] = bIndex * 10              ' Write Index*10 to each element of the array.'

Device = 16F88 ' We                         'll use a smaller device this time
Declare Xtal = 4                            ' Tell the compiler the device will be operating at 4MHz
Declare Hserial_Baud = 9600
Dim bMyArray[10] as Byte                    ' Create a 10 element Byte array.
Dim bIndex as Byte                          ' Create a Byte variable.

For bIndex = 0 to 9                         ' Repeat with bIndex= 0,1,2...9
 bMyArray[Index] = bIndex * 10              ' Write Index*10 to each element of the array.
 Next
 For bIndex = 0 to 9                        ' Repeat with Index= 0,1,2...9
 HRsoutLn Dec bMyArray [bIndex]             ' Show the contents of each element.
 DelayMs 500                                ' Wait long enough to view the values
Next



RGV250

#8
Hi,
That's the sort of think now it has been flagged up will probably be updated in the next update, it is correct in the example on the next page.
As far as I am aware the manual gets updated when the compiler is updated so should be current.
Don't forget, Les is the only person updating the compiler (and doing an excellent job of it) and cannot proof read almost 1000 pages(8 and 16 bit manuals), update the compiler and make a living at the same time.



Bob

John Lawton

Quote from: JackB on Dec 12, 2024, 07:24 PMThe 'Positron8 BASIC Compiler Manual'
since there's no revision date printed on the manual.

Au contaire, in my 8 bit manual which I believe is the latest, on page 2 it states:
"Revision 4.0.4.6 of the Manual." I assume this corresponds to the compiler version when the manual was last updated and the date of that version is held in the "Whats New.htm" file.

It used to be the case that there was no versioning in the manual but Les listened and has added it.

John


JackB

Thanks Bob, & John for pointing to source materials

found the document ""C:\Program Files (x86)\ProtonIDE\PDS\Docs\Whats New.htm""

from the beginning I used the manual online "https://sites.google.com/view/rosetta-tech/home"
and I'de like to point also by leaving a message about the code on page 51, was to let someone
know for the future manual update.
For many times Les, helped me a lot by taking the time to explain the "under the hood" different function
related to my inquiry.

Again I'd like to say that Les, interaction with the community on this forum is'Excellent' no doubt about it.

RGV250

Hi Jack,
Just in case you did not know, the manuals and Whats New can be found by going to Help / Documents in Positron.

Bob

trastikata

The current manual is easily accessible via the IDE: Help-Documents-Positron 8 / 16 Manual

Manual.jpg