|
-
Sep 30th, 2005, 10:26 PM
#1
Thread Starter
Fanatic Member
Read txt file[Resolved]
VB Code:
Open "C:\myfile.txt" For Append As #1
Print #1, "blah"
Close #1
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.
Last edited by emyztik; Sep 30th, 2005 at 11:46 PM.
-
Sep 30th, 2005, 10:33 PM
#2
Re: Read txt file
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
-
Sep 30th, 2005, 10:37 PM
#3
Re: Read txt file
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
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
|