Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

help with vbs

Posted on 2011-09-02
1
Medium Priority
?
331 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 93

Accepted Solution

by:
Patrick Matthews earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline
Suggested Courses

963 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