Solved

Vbscript needed for reading value from a file.

Posted on 2008-06-17
1
483 Views
Last Modified: 2012-05-05
I need to read the value of a parameter from a file.

Which code do I have to use if I the value of the parameter is present in the file in this format.

parameter1=value1
parameter2=value2

How can I retrieve eg. the value of parameter2 ?
0
Comment
Question by:itbabe
1 Comment
 
LVL 7

Accepted Solution

by:
Zippit earned 500 total points
ID: 21802120
Here is a function that will do so for you.
MsgBox getValue("C:\Documents and Settings\username\Desktop\sample.txt", "parameter1")
 
 
 
 

Function getValue(filePath, paramName)
 

    Dim fso     'As Scripting.FileSystemObject

    Dim ts      'As Scripting.TextStream

    Dim line    'As String

    Dim tokens  'As Variant

    Dim rv      'As String

    

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set ts = fso.OpenTextFile(filePath, ForReading)

    

    Do While Not ts.AtEndOfStream

        line = ts.ReadLine

    

        tokens = Split(line, "=")

        

        If Trim(LCase(tokens(0))) = Trim(LCase(paramName)) Then

            rv = tokens(1)

            Exit Do

        End If

    Loop
 

    Set fso = Nothing
 

    getValue = rv

End Function

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
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 …

932 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

12 Experts available now in Live!

Get 1:1 Help Now