search a value on a file usnig VBscript RRS feed

  • General discussion

  • hello , 

    i 'm new in vbscript , and i need your help , i have a file .ppt in this format :


    'Label;DefaultFreq;DefaultView;ZeroViewForNonadj;ZeroViewForAdj;[NONE];[NONE];UserDefined2;UserDefined3;SupportsProcessManagement;SecurityClass;MaximumReviewLevel;UsesLineItems;EnableDataAudit;DefFreqForICTrans;PhasedSubStartYear;Default Parent;Description(s)
    ICT;MTD;Periodic;Periodic;Periodic;[NONE];[NONE];;;Y;;2;N;N;MTD;;DefaultParent=#root;English=ICT PROTEIN


    'Label;DefCurrency;AllowAdjs;IsICP;AllowAdjFromChildren;[NONE];[NONE];UserDefined2;UserDefined3;HoldingCompany;SecurityAsPartner;Default Parent;Description(s)
    ICT_PERIMETER;EUR;N;N;N;[NONE];[NONE];;;;;DefaultParent=#root;English=PROTEIN Perimeter

    and i need to search  a value that exist in this file , for exemple i need to search  DefCurrency when Label=AE0100

    so to search the value , i need to search the position of !MEMBERS=ENTITY (because in this file i can found the same name of Label on differnet position) when i found it i need to search the value of DefCurrency .

    to open en read my file i use this code , but i con't found how to search the value

    ' Define needed I/O constants
    Const ForReading = 1
    Const ForWriting = 2
    Const TriStateUseDefault = -2

    ' Get input file name from command line parm
    If (WScript.Arguments.Count > 0) Then
       strInFile = WScript.Arguments(0)
       WScript.Echo "No input filename specified."
    End If

    ' Get output file name from command line parm (if none, overwrite input file)
    If (WScript.Arguments.Count > 1) Then
       strOutFile = WScript.Arguments(1)
       strOutFile = strInFile
    End If

    ' Create filesystem object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' Make sure input file exists
    If Not objFSO.FileExists(strInFile) Then
       Wscript.Echo "ERROR: Input file """ & strInFile & """ does not exist."
    End If

    ' Read entire file contents
    Set objFile = objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
    strData = objFile.Readall

    ' Split input data at line breaks
    arrData = Split(strData, vbCrLf)

    bIsEntity = false
    For i = 0 To UBound(arrData)
        ' Split fields at semi-colons
        arrField = Split(arrData(i), ";")

    if InStr(1, sLine, "!MEMBERS=ENTITY" , 1)  then
    bIsEntity = true
    elseif bIsEntity = true then
    if ubound(arrField)>0 then
    if arrField(1) = "AE0100" then
    mycurrency = aLine(1)
    'Exit Sub
    end if
    end if

    end if

        arrData(i) = Join(arrField, ";")


    ' Write output file with any changes
    Set objFile = objFSO.OpenTextFile(strOutFile, ForWriting, True)
    objFile.Write Join(arrData, vbCrLf)

    Function ZPad(strText, intLen)
        ' Pad with leading zeros on the left to specified length
        ZPad = Right(String(intLen, "0") & strText, intLen)
    End Function 

    thanks for your help

    • Changed type Bill_Stewart Friday, January 26, 2018 3:13 PM
    • Moved by Bill_Stewart Friday, January 26, 2018 3:13 PM This is not "scripts on demand"
    Tuesday, December 5, 2017 10:06 AM

All replies