Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Possible bug in MID$?
Author | Message | ||||
cosmic frog Senior Member Joined: 09/02/2012 Location: United KingdomPosts: 284 |
I may have found a bug in MID$, although it's probably more to do whith something I have done wrong. I've tracked it down to the example program below. It simply scrolls a message (which can change) held in mes$. It is this changing of mes$ which causes the program to lose track of the length of Len(m$). The program runs as it should for a few cycles but then m$ goes to zero and xx counts to 256 which causes the error. [13] m$=Mid$(mes$,xx,16) Error : 256 is invalid (valid is 1 to 255) Any thoughts will be welcome. PicoMite MMBasic Version 5.07.08b11 OPTION SYSTEM SPI GP2,GP3,GP4 OPTION AUTORUN ON OPTION LCDPANEL ILI9341, PORTRAIT,GP11,GP12,GP13 OPTION SDCARD GP5 OPTION AUDIO GP0,GP1, ON PWM CHANNEL 0 SetTick 150,call_scroll,1 Do Print @(10,10);"Len(mes$)=";Len(mes$);" Len(m$)=";Len(m$);" xx=";xx;" " Loop Sub call_scroll tim=tim+1:If tim=80 Then tim=0 If tim=1 Then mes$=" This is message one " If tim=48 Then mes$="This is message two " xx=xx+1:If xx=Len(mes$) Then xx=1 m$=Mid$(mes$,xx,16) Print m$ End Sub Thanks. Dave. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
Your xx keeps counting to 256, which is too large. Looks like a program bug. Before that it gets bigger than the length of mes$ so mid$ returns "" (zero-length string). Maybe a 2nd bug... John Edited 2023-08-24 06:59 by JohnS |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
xx=xx+1:If xx >= Len(mes$) Then xx=1 That should fix it. Jim VK7JH MMedit MMBasic Help |
||||
cosmic frog Senior Member Joined: 09/02/2012 Location: United KingdomPosts: 284 |
Thanks Jim. That seems to have fixed it. |
||||
Print this page |