Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing teh contents of a text file 1

Status
Not open for further replies.

cwalshe

Programmer
May 28, 2001
84
IE
Hi,
I have a text file that is passing data to a VB app. I need to clear the contents of the text file omce the data has been passed. (just clear the contents not erase the file).

Any ideas...

Cormac.
 
Why not just Write a number of Blank Lines???

Easy enough.. Although, killing and then creating would be the easiest way.

John Stephens
 
Open the text file for Output and then Close it, this deletes the contents of the file.
 
I have a similer question, but a little different. I've been looking through page after page of already answered questions looking for an answer, but could find none.

How would I replace a line of text in a txt file? If I can't just replace a line, is there a way to just take a line of text out of a file? What I have now looks for a string and if it's not there, adds it, but What I need next is if the string IS there, I need to replace it with a new one.

Dim Autobat As String
Autobat = FreeFile
Open "C:\Autoexec.bat" For Input As #Autobat
Line Input #Autobat, Data
If InStr(Data, "SET %INST=") = 0 Then
Close #Autobat
Open "C:\Autoexec.bat" For Append As #Autobat
Print #Autobat, "SET %INST=" + Left(drvInstall.Drive, 1)
Else
????
 
Cimso,
Your code only checks the FIRST line.
Code:
Private Sub Form_Load()
    Dim Autobat As Long
    Dim aryByt() As Byte
    Dim strFile As String
    Autobat = FreeFile
    Open "C:\Autoexec.bat" For Binary As #Autobat
    ReDim aryByt(LOF(Autobat))
    Get #Autobat, , aryByt
    strFile = StrConv(aryByt, vbUnicode)
    Close #Autobat

    If InStr(1, strFile, "SET %INST=", vbTextCompare) = 0 Then
        Autobat = FreeFile
        'Open "C:\Autoexec.bat" For Append As #Autobat
        'Print #Autobat, "SET %INST=" + Left(drvInstall.Drive, 1)
        'Close #Autobat
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top