Click to See Complete Forum and Search --> : how save text box information to file?
DGHall
Oct 31st, 1999, 06:18 PM
I know how to save information in a richtextbox to file, but the code doesn't work for a text box. Any suggestions?
chrisfricke
Oct 31st, 1999, 06:53 PM
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
DGHall
Nov 3rd, 1999, 07:28 PM
Great, thanks!!!
hmcheung
Jul 25th, 2000, 04:25 AM
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~~~
tomtan
Jul 25th, 2000, 04:33 AM
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
hmcheung
Jul 25th, 2000, 05:02 AM
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.... :(
To keep the formatting, pass rtfRTF as the flag.
RichTextBox1.SaveFile "C:\MyFile.rtf", rtfRTF
If you want to save in plain text format (ASCII), pass rtfText as the flag.
RichTextBox1.SaveFile "C:\MyFile.rtf", rtfText
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.