I have an app that simply saves urls what I need to do is verify that the app does not add duplicates to the text file any ideas
Printable View
I have an app that simply saves urls what I need to do is verify that the app does not add duplicates to the text file any ideas
Let's say that the variable that you want to add is VarURL, then:
Code:Dim AllURL As String
Open "Filename" for Input As #1
Get #1, ,AllURL
Close #1
If InStr(1, AllURL, VarURL, vbTextCompare) <> 0 then
VarURL = ""
End If
Open "Filename" for Output As #1
If VarURL<>"" Then Put #1, ,VarURL
Close #1
Microbasic when I run your code I get " Bad File Mode "
error any Idea why
Sorry, I forgot. You can't use Get+Put on Input+Append+Output files:
Code:Dim AllURL As String, Data As String, fr As Integer
fr = FileFree
Open "Filename" for Input As #fr
Do Until EOF(fr)
Line Input #fr, Data
AllURL = AllURL & " + " & Data
Loop
Close #fr
If InStr(1, AllURL, VarURL, vbTextCompare) <> 0 then
VarURL = ""
End If
fr = FileFree
Open "Filename" for Append As #fr
If VarURL<>"" Then Print #fr, ,VarURL
Close #fr
If the files start getting large, you might want to read the files as binary. It would look like this:
Code:
Private Const FILENAME = "test.txt"
Private Sub Command1_Click()
Dim FF As Long
Dim str_URL As String
Dim str_Test_URL As String
str_Test_URL = "http://zasdfzz.com"
FF = FreeFile
Open FILENAME For Binary As FF
str_URL = Space(LOF(FF))
Get #FF, , str_URL
If InStr(str_URL, str_Test_URL) = 0 Then
Put #FF, Seek(FF), str_Test_URL & vbCrLf
End If
Close FF
End Sub