Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 07:58 04 May 2024 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 : CMM2: difficulty with MID$

Author Message
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 10:37am 30 Aug 2020
Copy link to clipboard 
Print this post

This test program crashes when I try to set the last character in the string. I can't see anything I'm doing wrong.


option base 1
dim s$
s$="123"
print s$
mid$(s$,1,1)="."
print s$
mid$(s$,2,1)="."
print s$
mid$(s$,3,1)="."
print s$
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 10:51am 30 Aug 2020
Copy link to clipboard 
Print this post

I doesn't crash it just gives an incorrect error  
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1032
Posted: 11:20am 30 Aug 2020
Copy link to clipboard 
Print this post

Try these


s$ = "123"
s$ = left$(s$,2) + "."
print s$

12.

s$ = "123"
s$ = left$(s$,1) + "." + right$(s$,1)
print s$

1.3

s$ = "123"
s$ = S$ + "."
print s$

123.



BTW I think matherp was hinting that you should check the usage of MID$.
Edited 2020-08-30 21:41 by Chopperp
ChopperP
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 02:08pm 30 Aug 2020
Copy link to clipboard 
Print this post

  Chopperp said  Try these


s$ = "123"
s$ = left$(s$,2) + "."
print s$

12.

s$ = "123"
s$ = left$(s$,1) + "." + right$(s$,1)
print s$

1.3

s$ = "123"
s$ = S$ + "."
print s$

123.



BTW I think matherp was hinting that you should check the usage of MID$.


I guess I'll reread it in case I missed something.

From the manual:
  Quote  
MID$( str$, start [, num]) = str2$

The characters in 'str$', beginning at position 'start', are replaced by the characters in 'str2$'. The optional 'num' refers to the number of characters from 'str2' that are used in the replacement. If 'num' is omitted, all of 'str2' is used. Whether 'num' is omitted or included, the replacement of characters never goes beyond the original length of 'str$'.


so in my use, the characters in s$ (initially "123", and "..3" by the time of the last change) beginning at position 3, are replaced by the characters in ".". 1 character from "." is used in the replacement. Looks correct.

Did you see there's a command version as well as a function version?

  matherp said  I doesn't crash it just gives an incorrect error  


I think I might understand the distinction you're making. But I don't know if you mean it shouldn't give an error or should give a different error.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 03:15pm 30 Aug 2020
Copy link to clipboard 
Print this post

  Quote  But I don't know if you mean it shouldn't give an error or should give a different error.


It was a bug in the error checking - fixed in the 5.05.05 version Geoff has just uploaded
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 03:22pm 30 Aug 2020
Copy link to clipboard 
Print this post

Excellent!
 
Print this page


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

© JAQ Software 2024