Results 1 to 5 of 5

Thread: Question

  1. #1
    egiggey
    Guest

    Question

    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

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    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
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3
    egiggey
    Guest
    Microbasic when I run your code I get " Bad File Mode "
    error any Idea why

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    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


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width