|
-
Jul 18th, 2005, 09:56 AM
#1
Thread Starter
Hyperactive Member
textfile length
Hello, I have a form with a textbox and a timer. The timer is set to an interval of 600. When the timer fires, it loads C:\messages.text into a textbox. How can I have it do the following:
Check the linecount of the file, if it changed since the last time it opened..add the current time to the last line in the file. If that last line is blank...move back one until the current line isnt blank...then save the textfile.
Last edited by LostAngel; Jul 18th, 2005 at 10:10 AM.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Jul 18th, 2005, 10:30 AM
#2
Re: textfile length
VB Code:
Private Sub Timer1_Timer()
Dim hFile As Integer, sLines() As String, sText As String
Static nLines As Long
On Error Resume Next
hFile = FreeFile
Open "c:\message.txt" For Binary As #hFile
sText = Input(LOF(hFile), hFile)
Close #hFile
sLines = Split(sText, vbCrLf)
If UBound(sLines) <> nLines Then
Do While Right$(sText, 2) = vbCrLf
sText = Left$(sText, Len(sText) - 2)
Loop
sText = sText & vbCrLf & Now
nLines = UBound(Split(sText, vbCrLf))
Open "c:\messages.txt" For Output As #hFile
Print #hFile, sText
Close #hFile
End If
If Text1.Text <> sText Then
Text1.Text = sText
End If
End Sub
-
Jul 18th, 2005, 11:15 AM
#3
Thread Starter
Hyperactive Member
Re: textfile length
That code keeps adding the date & time to the textfile even when the file isnt changed...what i am wanting is for the program to detect when somethings added to the textfile...when its added...add the date/time to the end of the last line.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Jul 18th, 2005, 11:20 AM
#4
Re: textfile length
Oh yeah of course! When the file is saved a new newline is added to it. Change the code to this:
VB Code:
Private Sub Timer1_Timer()
Dim hFile As Integer, sLines() As String, sText As String
Static nLines As Long
On Error Resume Next
hFile = FreeFile
Open "c:\message.txt" For Binary As #hFile
sText = Input(LOF(hFile), hFile)
Close #hFile
sLines = Split(sText, vbCrLf)
If UBound(sLines) <> nLines Then
Do While Right$(sText, 2) = vbCrLf
sText = Left$(sText, Len(sText) - 2)
Loop
sText = sText & vbCrLf & Now
nLines = UBound(Split(sText, vbCrLf))
Open "c:\messages.txt" For Output As #hFile
Print #hFile, sText[b][color=red];[/color][/b] '<- Added a semicolon here
Close #hFile
End If
If Text1.Text <> sText Then
Text1.Text = sText
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|