Problem with Mid$

A forums to allow bugs and problems with Flowcode v6 to be reported and resolved.

Moderator: Benj

Post Reply
gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Problem with Mid$

Post by gtc »

According to the documentation:
Mid$(string,start,size)

Retrieves a substring from the string, starting at position start of size characters.
However, when I use Mid$ in Flowcode 6.0.2.1, as follows, where string A[20] has the value "123456789" :
Result = Mid$ (A,X,1)
Result[20] string receives the substring at position start+1, instead of position start.

That is, when index X =1, Result =2; when X = 2, Result =3; etc.

Simple demo program attached.
Attachments
Test_of_Mid$.fcfx
(3.99 KiB) Downloaded 281 times

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: Problem with Mid$

Post by DavidA »

Hi gtc,

Can you please try using the latest version of Flowcode, 6.1.2, i seem to recall an issue with some string functions were rectified in a later patch.

gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Re: Problem with Mid$

Post by gtc »

Hi,

Seems I was a tad dyslexic when I typed the above. In fact I am using version 6.1.2.0 (11.5.2015).

If you run my sample program under debug and step through the loop while watching the variables in the simulation window, you'll see what I mean.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Problem with Mid$

Post by medelec35 »

Hi gtc,
Since arrays start at 0 and not 1 you will need to retrieve the first character by Mid$(StringVar,0,size).

Mid$(StringVar,1,size) will start at the second char.

If you have a look at wiki help (Via Flowcode Help, Index) you will see that:
Wiki string.png
(8.51 KiB) Downloaded 3005 times

Martin
Martin

gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Re: Problem with Mid$

Post by gtc »

medelec35 wrote:Since arrays start at 0 and not 1 ...
Hi Martin,

Thanks. I had missed that point hidden in the example.

Matrix: please update that Wiki text entry to make clear the specific point that string arrays commence at position zero.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Problem with Mid$

Post by kersing »

Wiki has been updated.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply