|
-
May 18th, 2001, 08:13 AM
#1
Thread Starter
Addicted Member
Insert text at beginning of file
Hello,
Is it possible to add a line to the beginning of a textstream...or to read the textstream from .atendofstream and to the top? I need to write the contents to a textbox and need the newest entry (now appended at the end of the file) to be displayed first in the textbox...any ideas?
-
May 18th, 2001, 08:16 AM
#2
Lively Member
Seems like it would be much easier with a database
Real programs don't eat cache.
Pete 
-
May 18th, 2001, 08:21 AM
#3
Thread Starter
Addicted Member
It's just a log file so i don't really want to use a database...
-
May 18th, 2001, 08:34 AM
#4
_______
<?>
Code:
Private Sub Command1_Click()
Dim sFile As String, iNum As Integer
Dim myVar As String
sFile = "C:\my documents\myfile.txt"
iNum = FreeFile
Dim sArr()
Dim i As Integer
Open sFile For Input As iNum
Do Until EOF(iNum)
ReDim Preserve sArr(i)
Line Input #iNum, myVar
sArr(i) = myVar
i = i + 1
Loop
Close iNum
Open sFile For Output As iNum
Print #iNum, "my new line"
For i = 0 To UBound(sArr)
Print #iNum, sArr(i)
Next i
Close iNum
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
May 18th, 2001, 01:24 PM
#5
Addicted Member
Here is another option...
Code:
Private Sub BuildLogFile2()
'This uses a Temp File to save log info
'and then appends the temp file to the new log file.
Dim strFile1 As String
Dim strFile2 As String
Dim strTemp As String
Dim intNum1 As Integer
Dim intNum2 As Integer
strFile1 = "C:\My Documents\MyFile.log"
strFile2 = "C:\My Documents\~MyFileLog.bak"
'Do Clean up before processing
'Use Resume Next in case file doesn't exists
On Error Resume Next
Kill strFile2
'Now use Error Handler Routine
On Error GoTo errHandler
intNum1 = FreeFile
'Back Up the Log File (Just to be safe)
Name strFile1 As strFile2
'Create New Log File
Open strFile1 For Output As intNum1
Print #intNum1, "New Line " & Now
Close intNum1
DoEvents
'Append Old Log File to New Log File
Open strFile1 For Append As intNum1
intNum2 = FreeFile
Open strFile2 For Input As intNum2
Do Until EOF(intNum2)
Line Input #intNum2, strTemp
Print #intNum1, strTemp
Loop
Close intNum2
Close intNum1
'Clean Up
Kill strFile2
Exit Sub
errHandler:
'An Error occurred so set things back the way they were
Close intNum2
Close intNum1
Kill strFile1
Name strFile2 As strFile1
MsgBox Err.Description, vbOKOnly, "Error " & Err.Number
End Sub
-
May 18th, 2001, 02:32 PM
#6
Code:
Open "Myfile" For input as #1
tmp = input(lof(1),1)
close #1
Open "Myfile" for output as #1
print #1, "MyStr"
print #1, tmp
close #1
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
|