Incrementing character string ASCII value

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

Moderator: Benj

Post Reply
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

Post by Mark »

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: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Incrementing character string ASCII value

Post by LeighM »

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

Post by Mark »

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: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Incrementing character string ASCII value

Post by kersing »

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

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: Incrementing character string ASCII value

Post by medelec35 »

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 222 times
Martin

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: Incrementing character string ASCII value

Post by medelec35 »

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 221 times
Martin

Post Reply