New topic: Chr(c) yields "parameters not compatible.."
<http://forums.realsoftware.com/viewtopic.php?t=37961> Page 1 of 1 [ 8 posts ] Previous topic | Next topic Author Message tseyfarth Post subject: Chr(c) yields "parameters not compatible.."Posted: Sat Mar 05, 2011 10:13 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 156 Hello all. Using the following code, the compiler complains "Parameters not compatible with this function" Code: Dim c as string Dim buf as string dim i as Int16 buf = "" buf = serial1.ReadAll TextField1.Text = buf for i = 1 to len(buf) c = mid(buf,i,1) TextField1.Text =TextField1.Text +Chr(c) next i 'TextField1.Text = serial1.ReadAll Why cant the Chr(c) code be used here? Originally, I had a single line Code:TextField1.Text =TextField1.Text +Chr(mid(buf,i,1)) But that too failed with the same error. Anyone have any idea? Tim Top timhare Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sat Mar 05, 2011 10:27 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 9392 Location: Portland, OR USA What do expect the result of that code to be? You must be thinking of some other function, so if you describe what you want, maybe we can point you in the right direction. Chr() takes an integer and converts it into the character with the corresponding ascii value. Top tseyfarth Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sun Mar 06, 2011 12:14 am Joined: Sat Dec 04, 2010 9:14 pm Posts: 156 Hi Tim, Quote:Chr() takes an integer and converts it into the character with the corresponding ascii value. That is exactly what I wanted it to do. The data I expect to be in the Rxd buffer is on the order of ">CDEF01" and a carriage return. The remote device transmits ASCII Chars. However, this will not even compile. While if it got a non printable character, or a value not in the ascii table, I would expect a failure. Again, the issue here is, it will not even compile. Thank you for your response! Tim Top Indy Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sun Mar 06, 2011 12:31 am Joined: Wed Jul 09, 2008 10:46 pm Posts: 174 Location: Minneapolis c is a string chr() takes an integer chr(c) will not work _________________ http://www.miscjunk.org Top timhare Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sun Mar 06, 2011 12:46 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 9392 Location: Portland, OR USA OK, but given the string ">CDEF01", what do you want to turn it into? That does look like a hexadecimal number, is that what you want out of if? Mid() will yield a string, eg., Mid("CDEF01", 2, 1) is the letter "D". It's not a number, although you could interpret it as the hex digit D, which is decimal 13. The question is, how do you want to interpret the string? Sometimes simply posting code, especially non-working code, without an explanation of the exact behavior desired, isn't very helpful. Top tseyfarth Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sun Mar 06, 2011 12:51 am Joined: Sat Dec 04, 2010 9:14 pm Posts: 156 Indy, What you wrote is true. And must be the explanation. So, what is the best way to read each Byte of received data from the Serial port, which always comes in as strings, and convert to an asc char? I need to go back and look at my VB6 work. It all worked there perfectly but I must be missing something - or lots! I am just trying, at this point, to get Async Serial to work, which is proving harder than I thought - there are hardware issues (RTS), timing issues between devices (gotta pull the digital scope out), code issues and of course the newbie issue. Thanks to both of you for your responses! Tim Top tseyfarth Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sun Mar 06, 2011 12:56 am Joined: Sat Dec 04, 2010 9:14 pm Posts: 156 Sorry Tim I did not see your response while writing the last one. All I was trying to do, was to get that data ">CDEF... " to display in the text field. Not decode yet, just get a simple simple polling routine running to where I can visually see that the correct data is appearing in RB. Yes it is hex, a Start >, 4 byte address CDEF (52719 dec) and other stuff that I don't care about now. The problem I have so far, besides this, is that the Serial object does not fire everytime data is avail - or so it seems. LED's tell me that data is going out to the device, the device is receiving good packets, is replying. But most of the time there is nothing showing up in the text box. Will have another look tomarrow when fresh - been working since 9AM and it is 11PM now. I hear wings calling my name! Thanks again Tim! Tim Top timhare Post subject: Re: Chr(c) yields "parameters not compatible.."Posted: Sun Mar 06, 2011 3:01 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 9392 Location: Portland, OR USA Your earlier code accomplishes that. The data is already a string. No need to convert it byte by byte. Perhaps you had to do it that way in VB. Code:TextField1.Text = buf Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 8 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
