Cassie
02-06-2003, 03:23 AM
Hello! I'm having problem writing or saving string to a text file particularly into notepad. Here's my code:
DbaseString - variable for my string
Dim f, a
Dim inFileNumber As Integer
Dim strLine As String
Dim lngFileLength As Integer
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.DialogTitle = "Select a file name"
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files" & _
"(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowSave
MsgBox "Save to Path: " + CommonDialog1.FileName
intFileNumber = FreeFile
lngFileLength = FileLen(CommonDialog1.FileName)
Open CommonDialog1.FileName For Input As intFileNumber _
Len = lngFileLength
txtDocument.Text = Input$(lngFileLength, intFileNumber)
Close intFileNumber
Set f = fs.OpenTextFile(CommonDialog1.FileName, ForWriting, TristateFalse)
f.Write (DbaseString)
f.Close
Exit Sub
ErrHandler:
Exit Sub
---------
I'm not sure with the other codes. I just tried them and they work fine. I think what's lack in there is the saving or writing string into text file. Is this code,
f.Write (DbaseString)
suppose to write string to text file?
This codes is about locating the text file through commondialog box and then I want to save my string to that text file. Just overwrite any characters save in there if there is.
I will appreciate any of your help. Thank you in advance. :)
DbaseString - variable for my string
Dim f, a
Dim inFileNumber As Integer
Dim strLine As String
Dim lngFileLength As Integer
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.DialogTitle = "Select a file name"
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files" & _
"(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowSave
MsgBox "Save to Path: " + CommonDialog1.FileName
intFileNumber = FreeFile
lngFileLength = FileLen(CommonDialog1.FileName)
Open CommonDialog1.FileName For Input As intFileNumber _
Len = lngFileLength
txtDocument.Text = Input$(lngFileLength, intFileNumber)
Close intFileNumber
Set f = fs.OpenTextFile(CommonDialog1.FileName, ForWriting, TristateFalse)
f.Write (DbaseString)
f.Close
Exit Sub
ErrHandler:
Exit Sub
---------
I'm not sure with the other codes. I just tried them and they work fine. I think what's lack in there is the saving or writing string into text file. Is this code,
f.Write (DbaseString)
suppose to write string to text file?
This codes is about locating the text file through commondialog box and then I want to save my string to that text file. Just overwrite any characters save in there if there is.
I will appreciate any of your help. Thank you in advance. :)