Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:50 02 Aug 2025 Privacy Policy
Jump to

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
Guru

Joined: 09/02/2012
Location: United Kingdom
Posts: 302
Posted: 08:23pm 23 Aug 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4044
Posted: 08:57pm 23 Aug 2023
Copy link to clipboard 
Print this post

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: Australia
Posts: 6283
Posted: 08:59pm 23 Aug 2023
Copy link to clipboard 
Print this post

xx=xx+1:If xx >= Len(mes$) Then xx=1

That should fix it.

Jim
VK7JH
MMedit
 
cosmic frog
Guru

Joined: 09/02/2012
Location: United Kingdom
Posts: 302
Posted: 07:22am 24 Aug 2023
Copy link to clipboard 
Print this post

  TassyJim said  xx=xx+1:If xx >= Len(mes$) Then xx=1

That should fix it.

Jim


Thanks Jim. That seems to have fixed it.  
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025