More string questions

General discussion on mikroBasic PRO for 8051.
Post Reply
Author
Message
RAWWAR
Posts: 9
Joined: 21 Oct 2016 23:09

More string questions

#1 Post by RAWWAR » 30 Oct 2016 20:16

Hi,
again I am strugling with strings. In this case: manipulating them.
In al the basic dialects that I know of, there were statements like:
dim a as string[10], dim b as string[10]
a="1234567890"
then I used:
b = left (a,4) 'resulting in b=1234
or,
if left(a,3)="123" then....

So basically I am looking for the statements: Left, Right, or Mid(string).
Now, I found in a list of keywords, the words left, mid and right, as reserved words.
However no explanation of how to use them.
Starting with B=right( , I get a pop up that says "no parameters expected".
Can you explane how this should be used ?

Rob

RAWWAR
Posts: 9
Joined: 21 Oct 2016 23:09

Re: More string questions

#2 Post by RAWWAR » 02 Nov 2016 19:11

Unbelievable, well over 2000 views in 3 days. 700/day and
not ONE reply ? Not even from the helpdesk ? Anyone ?

Simple question I think: Is there an instruction like
Mid(string ), Right(string) and left(string) ? If not, why not ?
How are the keywords mid, left and right in the manual used ?
regards,
Rob

User avatar
nadir.celebic
mikroElektronika team
Posts: 465
Joined: 15 Jun 2016 13:19

Re: More string questions

#3 Post by nadir.celebic » 03 Nov 2016 17:50

Hi,

Unfortunately, Left, Right and Mid doesn't exist in our compilers, they are only reserved words, as with any other BASIC oriented language.
I write test program for Left and Right to show you how this work.
Middle works on the same principle.

Code: Select all

program Test

dim txt_destination as string[16]
dim txt_source as string[16]
dim string_length as word

sub procedure right_(dim str as ^char, dim character_place as byte)
dim temp as byte volatile
  
  string_length = strlen(str)
  temp = string_length - character_place
  memcpy(@txt_destination, @txt_source + temp, character_place)
end sub

main:
  txt_source = "mikroElektronika"

  ' left
  strncpy(txt_destination,txt_source,5)

  ' right
  right_(@txt_source, 11)
  asm nop end asm

end.
Regards,
Nadir

RAWWAR
Posts: 9
Joined: 21 Oct 2016 23:09

Re: More string questions

#4 Post by RAWWAR » 04 Nov 2016 22:06

Nadir, thanks for your reply.
I'am almost afraid to keep asking questions, but it still doesn't work as I expected.
I tried only the "left" example, because this example does not
need any self-written procedures, only the strncpy command.
To see the result, I send the result to the serial link.
The CRLF sends a CR+LF to the serial link. At least that works.

I used the following code:
txt_source = "mikroElektronika"
CRLF
UART1_Write_text(txt_source)
CRLF
strncpy(txt_destination,txt_source,6)
UART1_Write_text(txt_destination)

The result is:
mikroElektronika
mikroE456789
So basically it works: It prints the txt_source, a CR+LF
and the left 6 characters which are in txt_destination: mikroE
However, it also prints "456789", a left over from a previous test.
If I replace the 6, by a byte variable, the result is even more unbelievable:
So:
dim CC as byte
CC = 6
strncpy(txt_destination,txt_source,CC)
Result is:
mikroElektronika
mikroEektronika
as you see, somehow there is an "l" missing.
Both source and string vars are 16 bytes long, so that shouldn't be a problem.
What am I doing wrong this time ?
Hope to here from you soon. Regards,
Rob

User avatar
nadir.celebic
mikroElektronika team
Posts: 465
Joined: 15 Jun 2016 13:19

Re: More string questions

#5 Post by nadir.celebic » 07 Nov 2016 16:51

Hi,

Can you please send me your project in .zip, so I could test it?

Regards,
Nadir

RAWWAR
Posts: 9
Joined: 21 Oct 2016 23:09

Re: More string questions

#6 Post by RAWWAR » 07 Nov 2016 22:20

Nadir,
see the attachment. Despite the name ( test1), the file is located on D:\MBasic\Test0.
I hope you can tell me why things go wrong.
Regards,
Rob
Attachments
Test0.zip
(25.04 KiB) Downloaded 187 times

User avatar
nadir.celebic
mikroElektronika team
Posts: 465
Joined: 15 Jun 2016 13:19

Re: More string questions

#7 Post by nadir.celebic » 08 Nov 2016 17:51

Hi,

There is some problem with UART.
I recommend to check our examples for UART, maybe will help.

Please check example in attachment.

Regards,
Nadir
Attachments
Uart.zip
(35.05 KiB) Downloaded 169 times

RAWWAR
Posts: 9
Joined: 21 Oct 2016 23:09

Re: More string questions

#8 Post by RAWWAR » 08 Nov 2016 23:19

Nadir,
I looked at the file you uploaded. It looks pretty much the same
as the files in the example directory, which I used as a template.
My test or your example makes no difference: they don't work.
What do you mean: "some problem with the UART" ?
I initialize to 9600 baud and I am able to send a direct string
(UART1_Write_text("String Test"). So the uart seems to work.

How can it be that the routine: strncpy(txt_destination,txt_source,5)
with the string variables in ext. memory does not work ?
That has nothing to do with the uart I think. Has it ?

Why does a routine like UART1_Write_text(string) only work when the
string is in internal memory and not when in external memory ?

Please explane what I am doing wrong or if this is a compiler error ?

Regards, Rob

User avatar
nadir.celebic
mikroElektronika team
Posts: 465
Joined: 15 Jun 2016 13:19

Re: More string questions

#9 Post by nadir.celebic » 09 Nov 2016 17:27

Hi,

You are right, there is problem with those strings.

I will pass this to our developer team, then I will tell you more about this.

Regards,
Nadir.

RAWWAR
Posts: 9
Joined: 21 Oct 2016 23:09

Re: More string questions

#10 Post by RAWWAR » 09 Nov 2016 19:25

Nadir,
in that case you might want to ask them to implement the left, right and mid string statements as well ?
This could be done in... a few days or so ? :-)
Regards,
Rob

User avatar
nadir.celebic
mikroElektronika team
Posts: 465
Joined: 15 Jun 2016 13:19

Re: More string questions

#11 Post by nadir.celebic » 10 Nov 2016 16:32

Hi,

Unfortunately, currently I can't tell you with certainty.
This is pass to our developer team.

Regards,
Nadir

Post Reply

Return to “mikroBasic PRO for 8051 General”