News:

;) This forum is the property of Proton software developers

Main Menu

hrsout functionality for string creation

Started by Sommi, May 14, 2021, 04:25 PM

Previous topic - Next topic

Sommi

Hi there

I have been using hrsout for a long time and it is a very powerful command.

However I would like to use the functionality to create a string.

Creating strings with strn and str$ is somewhat complicated and needs storage in additional strings.

Example Hrsout:

Dim Voltage as Word
hrsout "Voltage",dec2 Voltage / 100,",",dec2 Voltage // 100,"V"

The same functionality for a new command or procedure:
Dim Voltage as Word
Dim S1 as String * 20
S1 = CreateString "Voltage",dec2 Voltage / 100,",",dec2 Voltage // 100,"V"

where Createstring would be the new command

Anybody any idea?

Regards Sommi

KISS - keep it simple and stupid

top204

#1
Use the Str$ function to convert an integer into a String and concatenate them into a String variable:

    Dim MyString As String * 20
    Dim Voltage As Word = 1234  
   
    MyString = "Voltage " + Str$(Dec2, Voltage / 100) + "," + Str$(Dec2, Voltage // 100) + "V"
    HRSOutLn MyString

The, tested, result on a serial terminal of the above code is: "Voltage 12,34V"

If using the latest Positron compilers, it can also be incorporated into a procedure:
'--------------------------------------------
' Transmit a string's contents to a serial terminal
' Input     : pString holds the string to transmit
' Output    : None
' Notes     : None

Proc SendString(pString As String * 20)
    HRSOutLn pString
EndProc
 
'--------------------------------------------
Main:
    Dim Voltage As Word = 1234  
   
    SendString("Voltage " + Str$(Dec2, Voltage / 100) + "," + Str$(Dec2, Voltage // 100) + "V")

The use of passing pieces of a string to a procedure as if they were being used to create a String variable is something I added to the Positron compilers. Sounds simple, but it was quite a major re-write of the procedural code and the String code within the compilers. :-)

Sommi

KISS - keep it simple and stupid

Sommi

MyString = "Voltage " + Str$(Dec2, Voltage / 100) + "," + Str$(Dec2, Voltage // 100) + "V"

this works with Positron8 however with Positron16 there is the error message:

Item "Voltage " not found.
KISS - keep it simple and stupid

Sommi

MyString = " Voltage " + Str$(Dec2 Voltage1 / 100) + "," + Str$(Dec2 Voltage1 // 100) + "V"

In Positron16 if there is a blank preceeding " Voltage " it works fine
KISS - keep it simple and stupid

top204

Thanks for finding the anomaly.

I'll correct this ASAP and upload a free update for the Positron16 compiler. It will also correct some signed comparisons that have a signed constant in them for the Positron16 compiler.


top204

Again... Many thanks for finding that anomaly...

It has now been corrected in Positron16. I had already made adjustments in Positron8 for that anomaly, but forgot to make the adjustments in the Positron16 source code.

It is caused by recursion of a function in the compiler's source code, so the initial parameter of the function that carries the name of the parameter in the line, keeps the first name instead of the holding the next name. It is because of silly pointers used extensively in C++, and these cause so many problems.

I'll be uploading a correction update that will simply replace the Pos16.exe file within the compiler's folder.