Horizon
Member in Training
Posts: 32
|
Post by Horizon on Apr 17, 2023 9:03:51 GMT
Hello, I'm struggling a bit with the file dialogue when saving an .csv file. In a nut shell I'll be putting the program output into a string and saved it in .csv format. I've simplified the example code below: [ExportCSV]
'Output as .csv
r$ = "MyFileName" myString$ = "Hello, You"
csv$ = ".csv"
filedialog "Save As...", r$, fileName$ 'Where r$ is the desired file name (if I change r$ to "*.csv" the file type is correct but the file name disappears?).
if fileName$<>"" then
open fileName$+csv$ for output as #f 'added the extension here so that it saves as the right file type (.csv)
print #f, myString$
close #f
else
notice "File not saved!"
end if
I found it necessary to add the .csv extension (csv$) so that when you do save as a file it's applied, but then the file type becomes generic in the filedialogue? It would be nice if the bottom of the file dialogue window appeared like this: File name: MyFileName.csv Save as type: *.csv Files I'm probably missing something obvious, but a point in the right direction would be appreciated
|
|
|
Post by Rod on Apr 17, 2023 9:59:37 GMT
Add the .csv to the filename when you open the file dialog forget about the *.csv that allows all .csv files to be seen rather than your specific filename.csv To be a bit clearer, if you have already chosen the file name why bother with filedialog. you might check if the file exists and offer a warning or pop up the filedialog in that special case, to offer a name change.
|
|
Horizon
Member in Training
Posts: 32
|
Post by Horizon on Apr 19, 2023 12:56:50 GMT
Hello Rod,
I see your point. I can always apply the extension to the file open dialogue. Thanks for the advice.
|
|