Results 1 to 7 of 7

Thread: how save text box information to file?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 1999
    Posts
    2

    Post

    I know how to save information in a richtextbox to file, but the code doesn't work for a text box. Any suggestions?

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111

    Post

    To save data from a text box (text1)

    open "Myfile.txt" for output as 1
    print #1,text1.text
    close #1

    If the text box is not multiline, this gives 1 line in the file. If it is multiline, then it gives lots of lines

    Cheers

    Chris

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 1999
    Posts
    2

    Post

    Great, thanks!!!

  4. #4
    Member
    Join Date
    Jun 2000
    Location
    Hong Kong
    Posts
    62

    Question doesn't work??

    I tried this code, but it's not 100% working with the rich text box. Sometimes all the Cr and Lf are gone and the file has only one line, and other times the cr and lf are there. strange~~~
    Please Visit My WebCam!!
    http://www.hmcheung.com

  5. #5
    Member
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    39
    From Help File(RichTextBox Control) :

    You can easily open or save an RTF file with the RichTextBox control by using the LoadFile and SaveFile methods. To open a file, use a CommonDialog control to supply the path name as shown:

    Private Sub OpenFile()
    ' The RichTextBox control is named "rtfData."
    ' The CommonDialog is named "dlgOpenFile."
    ' Declare a String variable for file name.
    ' Show the Open File dialog box, and set the
    ' variable to the filename.
    Dim strOpen As String
    dlgOpenFile.ShowOpen
    strOpen = dlgOpenFile.FileName
    ' Use LoadFile method to open the file.
    rtfData.LoadFile strOpen
    End Sub

    To save a file is just as easy, using the SaveFile method:

    Private Sub SaveFile()
    Dim strNewFile As String
    dlgOpenFile.ShowSave
    strNewFile = dlgOpenFile.FileName
    rtfData.SaveFile strNewFile
    End Sub

    ThOmaS TaN

  6. #6
    Member
    Join Date
    Jun 2000
    Location
    Hong Kong
    Posts
    62

    Thanks

    Thanks for your reply. The most crucial part is the .savefile method. the above code is also using this method and the problem is that the resulting txt file will lose all the formatting....
    Please Visit My WebCam!!
    http://www.hmcheung.com

  7. #7
    Guest
    To keep the formatting, pass rtfRTF as the flag.

    Code:
    RichTextBox1.SaveFile "C:\MyFile.rtf", rtfRTF
    If you want to save in plain text format (ASCII), pass rtfText as the flag.

    Code:
    RichTextBox1.SaveFile "C:\MyFile.rtf", rtfText

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