how can you read to check if "blah" already exists in the file? and if it does then don't write "blah" to it again.VB Code:
Open "C:\myfile.txt" For Append As #1 Print #1, "blah" Close #1
Printable View
how can you read to check if "blah" already exists in the file? and if it does then don't write "blah" to it again.VB Code:
Open "C:\myfile.txt" For Append As #1 Print #1, "blah" Close #1
VB Code:
Dim MyStr as string Open "C:\myfile.txt" For binary As #1 MyStr = input(lof(1),1) Close #1 If instr(MyStr,"blah") <> 0 then Open "C:\myfile.txt" For Append As #1 Print #1, "blah" Close #1 End if
Read thru the file to see if it exists. Try this out:
VB Code:
Option Explicit Private Sub Form_Load() Dim dup As Boolean dup = CheckForDups("blah") If dup = False Then Open "C:\myfile.txt" For Append As #1 Print #1, "blah" Close #1 End If End Sub Function CheckForDups(s As String) As Boolean Dim x As Integer, st As String Dim ff As Integer Dim strBuff As String Dim str() As String ff = FreeFile Open "C:\myfile.txt" For Input As #ff strBuff = Input(LOF(ff), ff) Close #ff str() = Split(strBuff, vbCrLf) For x = 0 To UBound(str) If s = str(x) Then CheckForDups = True Exit Function End If Next x CheckForDups = False End Function