Solved

help with vbs

Posted on 2011-09-02
1
274 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now