Results 1 to 4 of 4

Thread: saving data in a text file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Fremont Ohio 43420
    Posts
    253

    Question

    I'm having trouble saving data to a textfile. I can save the filename but cannot write the data to that file. Can someone help??
    Heres an example of the code I have so far:

    On Error Resume Next

    CommonDialog1.Filter = "All Text Files (*.txt)|*.txt"
    CommonDialog1.ShowSave

    strOpenFile = CommonDialog1.Filename

    Set ts = fso.CreateTextFile(strOpenFile, True)

    strData = Text1

    ts.Write (strData)
    ts.Close

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Rich text boxs have their own built in save feature

    Code:
    rtb1.savefile "C:\Myfile.txt" , rtfRTF 'to save
    
    rtb1.loadfile "C:\Myfile.txt" , rtfRTF 'to open

  3. #3
    Guest
    RichTextBoxes use up a lot more resources too. Next example will save data from Text1 into a file called MyFile.

    Code:
    Open "MyFile.txt" For Output As #1
    Print #1, Text1.Text
    Close #1

  4. #4
    Junior Member
    Join Date
    Aug 2000
    Posts
    25

    Thumbs up

    Sub SavetxtFile()

    'Assign constants forwriting numeric value
    Const ForWriting = 2

    'Set fso as object for writing to output file
    Set fso = CreateObject("Scripting.FileSystemObject")

    'Set SavetxtOutFile = file path
    Set SavetxtOutFile = fso.OpenTextFile _
    ("c:\windows\desktop\savedtxtfile.txt", ForWriting,True)

    'Write txt here
    SavetxtOutFile.write "Here is the text I have saved."

    'Close txt file
    Set SavetxtOutFile = Nothing

    End Sub

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