Solved

help with vbs

Posted on 2011-09-02
1
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

752 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