Reading from and writing to .txt files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NSF12345
    New Member
    • Aug 2006
    • 21

    Reading from and writing to .txt files

    I have managed to make a small program that writes data to a .txt file on close (to save settings that the user alters on program usage) but i need a way to read the settings (which are on one like at a time) and store them into integer variables. (I have seen ways of loading all the text in the file into a variable, but not one line at a time) All the data in the .txt file are numbers. Any ideas?

    In addition, when the data is stored in the .txt file, a space is at the start of each line. Anyidea's of how to stop this from happening?

    Here is the code that writes the data to the .txt file, I dont currently have code to read the file:

    Private Sub AppendTextToFil e()
    Dim intfile As String

    intfile = FreeFile
    Open "Settings.t xt" For Append As intfile
    Print #intfile, FrmMain.Top
    Print #intfile, FrmMain.Left
    Print #intfile, HScroll1.Value
    Close intfile
    End Sub

    This is just a test program before I start a bigger project. I will be having up to 10 lines of data in the .txt file, give or take, and that number will never change one the program is completed.

    Hope you can help
    Last edited by NSF12345; Aug 23 '06, 02:47 PM. Reason: Spelling
  • NSF12345
    New Member
    • Aug 2006
    • 21

    #2
    I could also do with a way to wipe the .txt file aswell, without deleting it and re-creating it. Thanks

    Comment

    • NSF12345
      New Member
      • Aug 2006
      • 21

      #3
      I done the readin the data, by putting it in an array (will show code if u want it) but i still cant get it to wipe the data in the .txt file. would still like help :)

      Comment

      • CaptainD
        New Member
        • Mar 2006
        • 135

        #4
        Open "Settings.t xt" For Output As #1
        Print #1, ""
        Close #1

        Comment

        • NSF12345
          New Member
          • Aug 2006
          • 21

          #5
          Originally posted by CaptainD
          Open "Settings.t xt" For Output As #1
          Print #1, ""
          Close #1
          Thanks, worked a treat!!

          Comment

          Working...