SaveAsDialog returning an error

Hi, guys,

I am having hard time with this code


Dim dlg as New SaveAsDialog
Dim f as FolderItem
dlg.InitialDirectory=SpecialFolder.Documents
dlg.promptText="Prompt Text"
dlg.SuggestedFileName="Suggested Filename"
dlg.Title="Title Property"
dlg.Filter=FileTypes1.Text  //defined as a file type in FileTypes1 file type set
f=dlg.ShowModal()
If f <> Nil then
  //file saved
Else
  //user canceled
End if

This line is returning an error.


dlg.Filter=FileTypes1.Text  //defined as a file type in FileTypes1 file type set

How can I fix it?

Thank you again for all your help.

Val

What is the error returned?
Are you sure the type is “Text” exactly, not “text/plain” or some such?

The error report reads

This item does not exist
dlg.Filer=FileTypes1.Text

The “FileTypes” is highlighted.

Thank you.

Val

Sounds like you don’t have a FileTypes1 set added to your project

Assuming that FileTypes1 is defined, then it should be:

dlg.Filter=FileTypes1

“Text” is not a property of FileType.

Assuming you DO have a FileTypes1, it doesn’t have a file type called text

Go to that line, delete .text
then press . and see what file types appear.
If text is not among them, you can add the text type to your FileTypes1 file set, using the second icon from the left on the filetypes editor screen.

That gives you a list of common file types.
Choose text from the drop down list

THEN the code will work as written

If you want all of your defined filetypes use:

dlg.Filter=FileTypes.All

If one had defined a file type as TEXT in a filetypes set named FileTypes1, then
dlg.Filter=FileTypes1.Text
would be proper.

Hi, guys,

Thank you for your feedback. Originally, I have not set the File Types set.

After setting the File Types set, I figured out the rest - with your help.

Is there any reference to read about the File Types Set? The Language Reference does not have much on this subject.

Thank you very much again.

Now it works.

Val

It should be covered in the User Guides. I wouldn’t expect much in the Language Reference, as it’s mostly an IDE thing.

Hi, guys,

I am stuck with the FileType again. I need to export several fields into a text file that could be read on either PC or Mac.

If I use the following FileType

DisplayName: Text
ObjectName: Text
MacType: TEXT
MacCreator: TEXT
Extension: TXT

Then Windows puts all lines of the text into one long line. TextEdit on a Mac opens it with no problem though

If I use the other FileType such as

DisplayName: Text
ObjectName: Text
MacType: RTF
MacCreator: RTF
Extension: rtf

Windows 7 opens it with either WordPad or MSWord with no problem, and Mac fails to open that rtf file at all.

What am I doing wrong?

Thank you.

Val

Whenever you open a text file on one OS that was created on a different OS, you have to deal with line endings. If you’re opening the file with a Xojo app, use ReplaceLineEndings to resolve the line ending differences. Otherwise, use an app like Notepad++ that will “fix” the line endings for you.

Hi, Tim,

I am trying to solve the problem via saving as pdf. My mac fails to open XOJO produced pdfs.

Val

How are you creating the pdf?

And how will you extract the text once you get it to the destination? This sounds like a rather complicated solution to a fairly simple problem.

I am creating a PDF via FileTypes “application/pdf.”

There is no need to extract information from the destination file - this is a report type file.

Also, I tried “application/rtf” - Mac refuses to open it.

Val

Xojo does not automatically create pdf files. You must use some specific platform-dependent mechanism, such as Mac’s ability to save a report as pdf, or a pdf printer driver on Windows. There are also a few frameworks you can use such as DynaPDF from Monkeybread Softare or the QuickPDF library fromDebenu.

I do not know what is wrong with XOJO creating RTF files.

Those files open with no problem on a PC and do not open on a Mac at all.

Just to make sure that Mac can open an RTF file, I installed a free application iText Express from the App Store.

TextEdit opens RTF files created with iTextExpress and fails to open files created with XOJO project (Windows opens them with WordPad).

Really weird stuff. Totally frustrating.

Val

How are you creating the rtf file? Are you writing out a TextArea’s RTFData? Based on your comment about pdf, I suspect you may be confused about what the filetype does. It simply marks the file as a particular kind of file (which isn’t necessary on Windows, as it’s based solely on the extension anyway). It is up to you to ensure that the contents of the file are formatted correctly.

Yes, Tim, you are right I was/am using a wrong way to format the data correctly.

Probably, I will stick with creating a text (.TXT) for right now and will open it on a PC with the right click and selecting WordPad. I need this to work on both PC and Mac.

Probably, it will take a while for me to find a way how to get content of several TextArea fields and write it into an RTF file.

I was using the following code


  Dim t As TextOutputStream
  
  Dim d as Date
  
  Dim dlg as New SaveAsDialog
  Dim f as FolderItem
  dlg.InitialDirectory=SpecialFolder.Documents
  dlg.promptText="Prompt Text"
  dlg.SuggestedFileName="UNTITLED FILE"
  dlg.Title="Title Property"
  dlg.Filter=FileTypes1.Text//defined as a file type in FileTypes1 file type set
  f=dlg.ShowModal()
  If f <> Nil then
    //file saved
  Else
    //user canceled
  End if
 
  
  if f <> nil then // f different from nil
    t = f.CreateTextFile // create file in selected location
    t.WriteLine ("PROJECT REPORT")
    t.WriteLine
    t.WriteLine
    t.WriteLine
    t.WriteLine"PARAMETER 1"
    t.WriteLine
    t.WriteLine (TextArea1.Text) // write date from TextArea to file
    t.WriteLine
    t.WriteLine
    t.WriteLine"PARAMETER 2"
    t.WriteLine
    t.WriteLine (TextArea2.text)
    t.WriteLine
    t.WriteLine
    t.WriteLine"PARAMETER 3"
    t.WriteLine
    t.WriteLine (TextArea3.text)
    t.WriteLine
    t.WriteLine
    t.WriteLine"PARAMETER 4"
    t.WriteLine
    t.WriteLine (TextArea4.text)
    t.WriteLine
    t.WriteLine
    t.WriteLine"PARAMETER 5"
    t.WriteLine
    t.WriteLine (TextArea5.text)
    t.WriteLine
    t.WriteLine
    t.WriteLine"PARAMETER 6"
    t.WriteLine
    t.WriteLine (TextArea6.text)
    t.WriteLine
    t.WriteLine
    t.Close // close file
  else
    // user cancelled
  end if

I will have to figure out how to do the same to write into RTF file. Like you said, I was under the impression that I only need to set the FileTypes to the appropriate extension.

Again, thank you for your guidance.

Val