Incrementing character string ASCII value

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Incrementing character string ASCII value

Postby Mark » Thu May 08, 2014 10:27 pm

Hi,

I am taking an existing file name, ABC01, and if present already, wanting to create a new name ABC02 to stop overwriting.
The file name is used in the FAT component.

Hence, I assumed that I would chop off the last character, increment it by 1, ASCII for '1' = 49 to get '2' fron ASCII 50 and then add it back to get the new name.

Char = Right$ (File_Name,1)
Char[0] = Char[0] + 1
Len = Length$ (File_Name)
File_Name = Left$ (File_Name, (Len - 1))
File_Name = File_Name + Char

File_Name_String = File_Name + ".csv"

what I get is test01.csv goes to test0ß.csv and then test0Ó.csv

What am I doing wrong? Is there a simpler way to do this?

Thanks,

Mark
Go with the Flow.

User avatar
LeighM
Matrix Staff
Posts: 1962
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 474 times
Been thanked: 674 times
Contact:

Re: Incrementing character string ASCII value

Postby LeighM » Fri May 09, 2014 11:43 am

It might help if you could post your Flowcode file so that we can see the string allocations.

Another way to do that would be:

filename[20]

filename = “ABC01.csv”
filename[4] = filename[4] + 1

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Re: Incrementing character string ASCII value

Postby Mark » Fri May 09, 2014 5:51 pm

Thanks,

I have tried your suggestion (using [4] + 1) with the result:

test01.csv goes to
test0.csv then
test .csv

It looks like something more is going on than simply incrementing an ASCII value. I will post further if something comes to light which might be helpful to others.
Go with the Flow.

kersing
Valued Contributor
Valued Contributor
Posts: 1894
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 541 times
Been thanked: 1058 times
Contact:

Re: Incrementing character string ASCII value

Postby kersing » Fri May 09, 2014 6:18 pm

Are these results in hardware or in simulation? Could you post your test code (fcfx file) ?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Incrementing character string ASCII value

Postby medelec35 » Sat May 10, 2014 12:58 am

Hi Mark,
I have attached one way it can be done.
Hope it works the way you would like it to?
here probably are more smarter ways, but due to the time of night it is, my poor brain is going for the easier option :lol:
If you can read the file name, you should be able to use the Compare string function to see if the name already exists.
If so using the method in attached flowchart, if the file name exists then string can go from Test01.csv to Test255.csv

Only testing in the simulator.

Martin
Attachments
File Naming.fcfx
(4.44 KiB) Downloaded 56 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8542
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3526 times
Contact:

Re: Incrementing character string ASCII value

Postby medelec35 » Sat May 10, 2014 11:00 am

Just remembered about the string bug within FC6
So it will work with numbers greater than 99 you will need to increase the array sizes of both strings by 1

Martin
Attachments
File Naming LCD.fcfx
(5.65 KiB) Downloaded 60 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.