Solved

Vbscript needed for reading value from a file.

Posted on 2008-06-17
1
486 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
[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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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…

733 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