Page 1 of 1

Incrementing character string ASCII value

Posted: Thu May 08, 2014 10:27 pm
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

Re: Incrementing character string ASCII value

Posted: Fri May 09, 2014 11:43 am
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

Re: Incrementing character string ASCII value

Posted: Fri May 09, 2014 5:51 pm
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.

Re: Incrementing character string ASCII value

Posted: Fri May 09, 2014 6:18 pm
by kersing
Are these results in hardware or in simulation? Could you post your test code (fcfx file) ?

Re: Incrementing character string ASCII value

Posted: Sat May 10, 2014 12:58 am
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

Re: Incrementing character string ASCII value

Posted: Sat May 10, 2014 11:00 am
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