Ascii control charaters in string variables

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
RichD
Posts: 6
Joined: 13 Feb 2018 12:17

Ascii control charaters in string variables

#1 Post by RichD » 26 Mar 2018 16:33

Can anybody help.
I seem to be struggling.
I need a string that contains only the ascii value 13 (a CR)
so I dimension a string - say CR_str
then I try CR_str=chr(13)
but I get an 'incompatibe types' error.
Obviously I'm mis understanding the use of 'chr'.
It seems the type expected is a byte.
so if I dimension X1 as byte
x1=chr(13) compiles ok, leaving x1=13
interesting but not what I need, and it does seem to make 'chr' a rather useless instruction, x1=13 would be a little easier so I must be missing something.
So what am I doing wrong here?
What is the easiest way to get a string containing a control characters or a combination of printable and control characters?

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Ascii control charaters in string variables

#2 Post by Dany » 28 Mar 2018 16:36

so I dimension a string - say CR_str
then I try CR_str=chr(13)
Indeed, the 'chr' function returns a character (the one with ascii code 13), not a string.
so if I dimension X1 as byte
x1=chr(13) compiles ok, leaving x1=13
Yes, bytes and characters are interchangeable in mB. The byte takes the ascii code of the character (as if the 'ord' function was used), the character takes the character with the ascii code of the byte (as if the 'chr' function was used).
What is the easiest way to get a string containing a control characters or a combination of printable and control characters?
Use e.g.

Code: Select all

S = "abc"
StrAppend(S, chr(13))
or

Code: Select all

S = "abc" + chr(13) + chr(10) + ...
Last edited by Dany on 24 Aug 2023 16:06, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

RichD
Posts: 6
Joined: 13 Feb 2018 12:17

Re: Ascii control charaters in string variables

#3 Post by RichD » 03 Apr 2018 16:50

Thanks for taking to time to look at that for me.
I should be able work around the issue I was having and move forward with that information.

Post Reply

Return to “mikroBasic PRO for AVR General”