Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading from and writing to .txt files

Newbie
 
Join Date: Aug 2006
Posts: 21
#1: Aug 23 '06
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 AppendTextToFile()
Dim intfile As String

intfile = FreeFile
Open "Settings.txt" 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

Newbie
 
Join Date: Aug 2006
Posts: 21
#2: Aug 24 '06

re: Reading from and writing to .txt files


I could also do with a way to wipe the .txt file aswell, without deleting it and re-creating it. Thanks
Newbie
 
Join Date: Aug 2006
Posts: 21
#3: Aug 24 '06

re: Reading from and writing to .txt files


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 :)
Familiar Sight
 
Join Date: Mar 2006
Posts: 135
#4: Aug 24 '06

re: Reading from and writing to .txt files


Open "Settings.txt" For Output As #1
Print #1, ""
Close #1
Newbie
 
Join Date: Aug 2006
Posts: 21
#5: Aug 24 '06

re: Reading from and writing to .txt files


Quote:

Originally Posted by CaptainD

Open "Settings.txt" For Output As #1
Print #1, ""
Close #1

Thanks, worked a treat!!
Reply