Does anyone have a function/method that generates a filename from the current date/time stamp?
Xojo’s funky string concatenation is causing issues with my “normal” methodology used in other languages.
Thanks.
Does anyone have a function/method that generates a filename from the current date/time stamp?
Xojo’s funky string concatenation is causing issues with my “normal” methodology used in other languages.
Thanks.
dim dt as new date
dim s="myfile_"+dt.sqldate+".dat"
s=replaceall(s,"-","_")
would return “myfile_2017_01_23.dat”
dim dt as new date
dim s="myfile_"+dt.sqldatetime+".dat"
s=replaceall(s,":","_")
s=replaceall(s," ","_")
s=replaceall(s,"-","_")
would return “myfile_2017_01_23_09_32_27.dat”
modify as you see fit
Thanks Dave. My issue appears to be memory allocation when I concatenate strings. Embedding the file naming string into the Dim statement solves the issue.
Thanks again.
-Scott.
As is Dave’s code doesn’t compile
dim dt as new date
dim s as string=“myfile_”+dt.sqldatetime+".dat"
s=replaceall(s,":","")
s=replaceall(s," “,”")
s=replaceall(s,"-","_")
The one time he doesn’t put the disclaimer…
[quote=311462:@Norman Palardy]
dim dt as new date
dim s as string="myfile_"+dt.sqldatetime+".dat"
s=replaceall(s,":","_")
s=replaceall(s," ","_")
s=replaceall(s,"-","_")
[/quote]
or my version by cascading the replaceall’s on one line.
dim dt as new date
dim s as string="myfile_"+dt.sqldatetime+".dat"
s=s.replaceall(":","_").replaceall(s," ","_").replaceall(s,"-","_").replaceall(s,"/","_")
Do be careful about this kind of usage of chained method calls
In this case its likely safe but there can be surprises
http://blog.xojo.com/2016/07/15/untie-these-chains-a-riddle/
and
http://blog.xojo.com/2016/07/15/untie-these-chains-solution/
[quote=311474:@Norman Palardy]Do be careful about this kind of usage of chained method calls
In this case its likely safe but there can be surprises
http://blog.xojo.com/2016/07/15/untie-these-chains-a-riddle/
and
http://blog.xojo.com/2016/07/15/untie-these-chains-solution/[/quote]
I normally dont do it but in this case I always do and have awesome luck with it.
That post of mine came from a bug report that a user sent in
Just saying there CAN be unexpected behaviour
Most times it works as expected but there are fringe cases where it might not - like that one in the blog post