+ Post New Thread
Results 1 to 5 of 5
Coding Thread, another VBScript question! in Coding and Web Development; Here goes.....! I have a file called errors, I want to compare the results of the error file with a ...
  1. #1
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Posts
    1,587
    Thank Post
    2
    Thanked 27 Times in 21 Posts
    Rep Power
    30

    another VBScript question!

    Here goes.....!

    I have a file called errors, I want to compare the results of the error file with a larger file called persistant.

    I want to read the first line of Errors and see if it's in Persistant
    I need to do this for every line of errors.

    Basically
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    set str1=objFSO.OpenTextFile("errors.txt")
    Set str2=objFSO.OpenTextFile("persistant.txt")

    Do While Not str1.AtEndOfStream

    com1=str1.ReadLine
    com2=str2.ReadLine

    If com1 = com2 then
    wscript.echo "Match"
    Else
    WScript.Echo "Not Match"
    end if

    Loop

    str1.close
    str2.close

    This doesn't work, but you get the idea!
    can someone point me in the right direction please!

  2. #2
    limbo's Avatar
    Join Date
    Aug 2005
    Location
    Birmingham
    Posts
    460
    Thank Post
    2
    Thanked 41 Times in 36 Posts
    Rep Power
    25

    Re: another VBScript question!

    Basically you need to have one loop inside another.

    So:-
    1 open the errors.txt file
    2 Get the next (first) errors.txt line
    3 Open the persistant.txt file
    4 Get the next (first) persistant.txt line
    5 Compare the two lines
    6 go back to 4 until you reach the end of the persistant.txt file
    7 go back to 2 until you reach the end of the errors.txt line
    8 Close everything

    Basically you are opening the first file, then comparing it to every line in the second file, then getting getting the next line and comparing it to every line in the second file again.

    Might take some time if you have large files - and there are probably smarter ways, but this is the easier way to get going.

    You have all the elements in your code, you just need to reorder them a bit and stick an extra couple of bits in

  3. #3
    limbo's Avatar
    Join Date
    Aug 2005
    Location
    Birmingham
    Posts
    460
    Thank Post
    2
    Thanked 41 Times in 36 Posts
    Rep Power
    25

    Re: another VBScript question!

    Not tested it - but try this
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set str1 = objFSO.OpenTextFile("c:\errors.txt")
    Set str2 = objFSO.OpenTextFile("c:\persistant.txt")

    Do While Not str1.atEndOfStream

    com1 = str1.ReadLine

    Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
    Do While Not str2.atEndOfStream
    com2 = str2.ReadLine
    If com1 = com2 Then
    WScript.Echo "Match"
    Else
    WScript.Echo "Not Match"
    End If
    Loop
    str2.Close
    Loop


    str1.Close
    This will flash up everytime it matches or does not match a line - if you want it to just flash once for the file, which I am guessing you do then instead of outputting "Match" when it finds it set a variable like ismatch=true

    Then when you get to the end output if ismatch=true then "Match" etc..

    Just make sure you set ismatch to be false at the beginning of the code somewhere.

    Edit - decided to just do it and add it instead of trying to describe it

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set str1 = objFSO.OpenTextFile("c:\errors.txt")
    Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
    ismatch = False
    Do While Not str1.atEndOfStream

    com1 = str1.ReadLine

    Set str2 = objFSO.OpenTextFile("c:\persistant.txt")
    Do While Not str2.atEndOfStream
    com2 = str2.ReadLine
    If com1 = com2 Then
    ismatch = True
    End If
    Loop
    str2.Close
    Loop


    str1.Close

    If ismatch = True Then
    wscript.echo "Match"
    Else
    wscript.echo "Not Match"
    End If

  4. #4
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Posts
    1,587
    Thank Post
    2
    Thanked 27 Times in 21 Posts
    Rep Power
    30

    Re: another VBScript question!

    Thanks for that Limbo, it was more of the 1st I was looking for than the 2nd.

    A bit of choping and changing and it's sorted thanks, I knew it was the looping that was going awray, just wasn't able to figure out why, so thanks for that!!

  5. #5
    limbo's Avatar
    Join Date
    Aug 2005
    Location
    Birmingham
    Posts
    460
    Thank Post
    2
    Thanked 41 Times in 36 Posts
    Rep Power
    25

    Re: another VBScript question!

    We aim to please!

SHARE:
+ Post New Thread

Similar Threads

  1. VBScript / SQL Server
    By Gatt in forum Scripts
    Replies: 7
    Last Post: 23rd September 2011, 03:21 PM
  2. VBScript IDE + Debugger
    By Geoff in forum Scripts
    Replies: 4
    Last Post: 13th September 2007, 08:56 PM
  3. VBScript Error
    By sqdge in forum Scripts
    Replies: 20
    Last Post: 13th September 2007, 03:34 PM
  4. VBScript
    By StewartKnight in forum Coding
    Replies: 5
    Last Post: 1st May 2007, 11:04 AM
  5. Printer vbscript ?
    By mac_shinobi in forum Scripts
    Replies: 1
    Last Post: 14th September 2005, 08:21 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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