Just curious! [sig]<p>MichaelRed<br><a href=mailto:mred@duvallgroup.com>mred@duvallgroup.com</a><br>There is never time to do it right but there is always time to do it over[/sig]
I must autmatic edit a text file. The User is not allowed to see this. I can't open a file in VB, because the files are to great (>64 kb!). Or can anyone tell me how I edit the only the first row in a file and save it back?
Well, how I do it is by using Text Streams. The only problem with them is that it is that you need to read the file into a variable by using FileSystemObjects. If you have a large file, I would recommend using a few variables. To start, access your references from the Project menu and look for "MS Scripting Runtime". The generic code goes a little something like this:
To Read the first line into memory:
Option Base 1
Dim mFSO as New FileSystemObject, mFile as File
Dim mTS as TextStream, arData(# of lines in file) as string
Private Sub Form_Load()
Dim s as String, i as Integer
Set mFile = mFSO.GetFile([path & filename])
Set mTS = mFile.OpenAsTextStream(For Reading)
s= mTS.ReadLine
for i = lbound(arData) to ubound(arData)
arData(i) = s
s = mTS.ReadLine
Next i
TS.Close
End Sub
Now you have the file in arData to do with what you want.
To edit the first line just modify the contains of arData(1) and life is good. Make sure you dont forget Option Base 1 in the declarations. [sig]<p>Halo<br><a href=mailto:Halo333@juno.com>Halo333@juno.com</a><br>[/sig]
Is the file delimited by linefeeds or carrage returns??? How did you create the file? Look to see if the file has line feeds at the ends then all you have to do is write a routine to reat the file line by line writing it out to a new file like this:
Warning: Untested code comming from my head:::
MyFile_in = FreeFile
Open "filename" for Input as MyFile_in
MyFile_out = FreeFile
Open "filename" for Output as MyFile_out
Do While Not EOF(MyFile_in)
Line Input #MyFile_in, Stuff
'Do somthing with the first line like If this is the first line...
'ya-de ya-de ya-de
At least don't open the same filename for In and out -
V E R Y c O n F U s I n G
[sig]<p>MichaelRed<br><a href=mailto:mred@duvallgroup.com>mred@duvallgroup.com</a><br>There is never time to do it right but there is always time to do it over[/sig]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.