Solved

help with vbs

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

15 Experts available now in Live!

Get 1:1 Help Now