Results 1 to 5 of 5

Thread: A problem saving files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    Posts
    30
    Well the title says most, and i thank everyone who helped me with my last problem. But right now i was working on creating my own small wanna-be notepad. But when i use the function:

    Form1.CommonDialog1.Filter = "Text Files (*.TXT)|*.TXT|All Files (*.*)|*.*"
    Form1.CommonDialog1.ShowSave
    Form1.RichTextBox1.SaveFile (Form1.CommonDialog1.FileName)
    Form1.Caption = Form1.CommonDialog1.FileName & ""

    Then save through that it gives you all sorts of garbage before the text you really want is shown. An Example of what i mean. The text is suppose to be test, but it comes out like this:

    {\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fswiss MS Sans Serif;}}
    {\colortbl\red0\green0\blue0;}
    \deflang1033\pard\plain\f2\fs17 --> test <--
    \par }
    I went and tried to look for other examples but they were using things like
    cd1.ShowSave
    And stuff like that, and when i searched through the code it had nothing declaring cd1.
    Please help, thanks!
    Dreys
    "Your worst enemy is your greatest teacher."

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Looks like it's saving it as rich text rather than plain text. If you open up a rich text file that you've made with just the text "Test" in it then I'll bet that would give you almost if not completely identical results.

    I don't know much about the common dialog, so all I can say is make sure you're using plain text and not rich text.
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    cd1 is probably the commondialog control which is what you leaved named CommonDialog1, use that name instead.
    Also to make the cancel button work, you need to activate the cancelerror, set it to true in the commondialog properties. Then make a simple error handler for it
    Code:
    on error resume next
    If Me.Parent = Nothing Then 
    with form1
      .CommonDialog1.Filter = "Text Files (*.TXT)|*.TXT|All Files (*.*)|*.*" 
      .CommonDialog1.ShowSave 
      if err then exit sub'or function or whatever
      .RichTextBox1.SaveFile (Form1.CommonDialog1.FileName) 
      .Caption = Form1.CommonDialog1.FileName & "" 
    end with
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Smile More formats - more power

    You can save the contents of your rich textbox in two different formats:

    a) with formatting (bold, different sizes, colors, etc.)
    b) Straight forward normal boring old text (like notepad)

    The SaveFile method has two parameters. The first is the filename of the file you are saving, and the second specifies in which of the two formats you want to save your file. Since you do not specify the second parameter, it defaulted to RTF format, which gave you all the garbage you saw.

    So basically, there is nothing wrong with the way you are using the common dialogue control. Try this instead:
    Code:
      'For normal text
      RichTextBox1.SaveFile (Form1.CommonDialog1.FileName, rtfText)
      'For formatted text
      RichTextBox1.SaveFile (Form1.CommonDialog1.FileName, rtfRTF)
    When you save normal text, your file should be saved as .txt, but when you save with formatting, be sure to use the .rtf extension.

    You can make your program better than Notepad, by allowing the user the choice of formatted or non-formatted text.

    Hope this helps.
    Shrog

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    Posts
    30
    Cool thanks a lot for the help!
    Dreys
    "Your worst enemy is your greatest teacher."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width