Not Working Example

The SaveAsDialog example DOES NOT WORKS on a genuine, unchanged OS properties (Windows 8.1); for your convenience, I pasted the example below:

[code]Dim dlg as New SaveAsDialog
Dim f as FolderItem

Dim txtType as New FileType
txtType.Name = “Text File (*.txt)”
txtType.MacType = “TEXT”
txtType.Extensions = “txt”

Dim htmlType As New FileType
htmlType.Name = “HTML File (*.htm, *.html)”
htmlType.MacType = "HTML "
htmlType.Extensions = “htm”

Dim csvType as New FileType
csvType.Name = “CSV File (*.csv)”
csvType.MacType = “TEXT”
csvType.Extensions = “csv”

Dim xlsType As New FileType
xlsType.Name = “Excel File (*.xls)”
xlsType.MacType = "XLS "
xlsType.Extensions = “xls”

dlg.promptText=“Prompt Text”
dlg.SuggestedFileName=“Suggested Filename”
dlg.Title=“Title Property”
dlg.Filter=txtType + htmlType + csvType +xlsType
If f <> Nil then

If Right(f.Name,3)=“txt” Then
MsgBox “1”
Elseif Right(f.Name,3)=“htm” Then
MsgBox “2”
Elseif Right(f.Name,3)=“csv” Then
MsgBox “3”
Elseif Right(f.Name,3)=“xls” Then
MsgBox “4”
End if

//user canceled
End if[/code]

The example above is unchanged from the Language Reference.

BTW: if you check the code, you may say “It works !” and I will answer: "Yes, but it is because you changed ONE Windows important behaviour: the file extension property. That property is set to “Do not show” by default on every Windows version I used thru the time (down to Windows 2.12 I think).
f.ExtensionVisible is False (watch in the debugger) so right(f.Name,3) cannot be compared to a file extension !
On the debugger, you can see that f.DisplayName and f.Name does not have the file extension (all xxxPath does not displays the file extension too).
Type, MacCreator and MacType are useless here.


I do not really understand if I can change this value TEMPORARY, for this blovk of code only (no if I correctly read the documentation).

At last, I am curious to know what happens on an OS X machine with file extension set to invisible (manufactory default settings): probably the same.

Nota: I know that I can change Windows File Extension visibility. BUT: the average Joe Newbie (is there’s one ?) do not. I met some people who set that flag to visible in their Windows machine, but do not know nor understand why !!!

In the mean time, I set manually .txt in the save as dialog and I was able to test the contents of the file I save (and it is good).

I borowed a MacBoook Pro yesterday for a week and was able to make this test:

the example works fine with Mavericks even after I set the file extensions back to invisible.

Better (bnut not surprising), the .text string appears in the debugger in DisplayName, Name, and all xxxPath properties.

Confirmed. This has been around for years.

To be clear, the bug is that the filename is not having .xls, .txt or whatever extension you expect ADDED to the filename by Windows / Xojo where it is missing.
The formats combo only serves to filter the contents of the displayed folder

Interestingly, the equivalent example of this that I found on the web for .NET does not use the extension to work out what you are saving, but the filter index . So it says ‘if you selected the third type of file, you must be wanting an XLS file’…
The filter index is not a property of the Xojo aveAsDialog class, however

It might be possible to use an OLEObject to drive the native windows dialogs, perhaps from the CommonDialog ActiveX

This is where the .name and the .displayname should differ.
If Windows is hiding the extension from view, that should affect the display name, but not the name or the absolute path

Yes. But I always saw these two properties with the same contents (on both OS X and Windows)

You should check f.type against your
If break your code after f<>nil you will see that f.type will be, for a text file for example, text/plain.


thanks for the tip.

I checked these (Type, MacType and MacCreator) before creating this conversation, but I do not added a file type (in the Navigation pane) and so these properties are empty. This is a test to do.

I only used these kind of file type and no Type property there:

Dim txtType as New FileType

txtType.Name = "Text File (*.txt)" txtType.MacType = "TEXT" txtType.Extensions = "txt"

I> have made some more testing earlier today.

a. When you save a Xojo new project, you do not type the project file extension.
b. If you do the same with the LR provided code, there will not be any file extension added
c. You fall in a trouble for a 40 years quest alone in the desert.
d. If you not add a file extension, your text file (what I tested) will be used as a test file by Windows 8.1, just like if yit have a file extension (what it does not have).

BUT, if you add “.txt” as the file extension, the code will runs OK, the file will not be seen with a file extension (if you do not modify the “Hide file extension” Windows 8.1 property) unless you ask to see the file properties and saw there the infamous .txt file extension.

Life is easy, but not as easier than Xojo is.