Jump to content
Sign in to follow this  
peterae

String=string+chr(byte)

Recommended Posts

Hi

Firstly i love this boostbasic,I cant wait for the full release.

Ok my problem is that i want to use the Chr Function,

I am reading a byte from the serial port as follows

 

Dim Dat as byte

Dim Buffer as String

 

if pir1.RCIF = 1 then ' if a character is received then

Dat = rcreg

Buffer = Buffer + Chr(Dat) 'append rs232 character to Buffer

....

 

I cant see any reference to any functions like this, is there a way i can transform Dat which is a Byte to a String Character.

 

Also

 

sub main()

Dim ErrorPos as Integer

Dim DeadBand as Integer

Dim Sum as Integer

' this works

Sum = ErrorPos + DeadBand

If Sum < 0 then

Goto notnearpos

End if

goto indeadband

' this doesnt

If ( ErrorPos + DeadBand ) < 0 then

goto notnearpos

End if

 

notnearpos:

 

indeadband:

end sub

 

***********************

also this doesnt fail gracefully

 

Dim Buffer(10) as byte

sub main()

 

call BufAdd()

 

end sub

 

sub BufAdd()

Buffer = ""

Buffer(0) = 0

End sub

 

I know theres a deliberate mistake but boost basic gives an access violation.

 

Keep up the good work

Peter

Edited by peterae

Share this post


Link to post
Share on other sites

peterae,

 

Here is a solution:

 

function Chr( c as char ) as string( 2 )

asm movf _c, W
asm movwf _Chr
asm movlw 0
asm movwf _Chr+1

end function

Sub main() 
Dim c As char

dim buffer(20) as string
dim dat(2) as string

buffer = "hello"
c = 65

buffer = buffer + call Chr( c ) 'append rs232 character to Buffer


Do while 1



Loop



end sub

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...