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
Solved

Vbscript needed for reading value from a file.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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