?
Solved

Vbscript needed for reading value from a file.

Posted on 2008-06-17
1
Medium Priority
?
488 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

762 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