Solved

help with vbs

Posted on 2011-09-02
1
305 Views
Last Modified: 2012-06-27
got a text file that looks like

aaa|bbb|sss
vvv|bbb|ccc

What I want to do is to open the txt file and search for bbb.
If the string is found then output  string bbb "found"  if not then "not found".
The output message should be displyed just once.  I dont need the output message found/not found to be displayed per line.

Does anybody knows how to do this?
0
Comment
Question by:kt2003
1 Comment
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36477865
Something like this...



Dim fso, ts, line, arr, result, counter

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("c:\Input.txt")
result = False

Do Until ts.AtEndOfStream
    line = ts.ReadLine
    If line <> "" Then
        arr = Split(line, "|")
        For counter = LBound(arr) To UBound(arr)
            If arr(counter) = "bbb" Then
                result = True
                Exit Do
            End If
        Next
    End If
Loop

ts.Close
Set ts = Nothing
Set fso = Nothing

If result = True Then
    MsgBox "Found"
Else
    MsgBox "Not found"
End If

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question