how can I opena file,
count the number of lineCode:Open "c:\windows\desktop\test1.txt" For Input As #1
and add a new line in the file ...
ex.:
before:
Line1
line2
After:
Line1
Line2
Line3
cause now, my code do that :
Line1Line2Line3
Printable View
how can I opena file,
count the number of lineCode:Open "c:\windows\desktop\test1.txt" For Input As #1
and add a new line in the file ...
ex.:
before:
Line1
line2
After:
Line1
Line2
Line3
cause now, my code do that :
Line1Line2Line3
Here's how to read a text file:
And to save it:Code:Open "MyFile" For Input As #1
Text1.Text = Input$(LOF(1), 1)
Close #1
[Edited by Matthew Gates on 09-10-2000 at 02:53 AM]Code:Open "MyFile" For Output As #1
Print #1, Text1.Text
Close #1
Ok..
there is no way to UPDATE the file..
so..
it,s because it will be a log fil of all a year..
in all a scool..
Well, if you want to add to the end of it:
Code:Open "MyFile" For Append As #1
Print #1, Text1.text
Close #1
Working with files you should use the Freefile function:
FreeFile supplies a file number that is not already in use.
Dim intNum as integer
intNum = Freefile
Open "yourpath/yourfile.ext" for Append as Intnum
You can open tons of files this way and never have to keep track of the file numbers used. #1,#2,#3
have fun!Code:Dim fn As FreeFile, i as Long
Open FILE for Input As #fn
Do While Not EOF(fn)
Line Input #fn, MyStr
i = i + 1
Loop
Close
MsgBox "Your file contains " & i & " lines!"
Did ...
... Will add a line before put a new data :Code:Open "MyFile" For Append As #1
Print #1, Text1.text
Close #1
BEFORE1
BEFORE2
AFTER
Or:
BEFORE1
BEFORE2AFTER
'this is the content of myfile.txt before
Before
Before2
Before3
[code]
Option Explicit
Private Sub Form_Load()
Text1 = "This is after I append"
Dim myFile As String
Dim intNum As Integer
myFile = "C:\my documents\myfile.txt"
intNum = FreeFile
Open myFile For Append As intNum
Print #1, Text1.Text
Close intNum
End Sub
[code]
'this is it after running the above
Before
Before2
Before3
This is after I append
Ok..
thak's it's exactly what I need..
:)