none
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 :

    !CURRENCIES
    'Label;Scale;TranslationOperator;DisplayInICT;Description(s)

    !MEMBERS=SCENARIO
    '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

    !HIERARCHIES=SCENARIO
    ;ICT

    !MEMBERS=ENTITY
    'Label;DefCurrency;AllowAdjs;IsICP;AllowAdjFromChildren;[NONE];[NONE];UserDefined2;UserDefined3;HoldingCompany;SecurityAsPartner;Default Parent;Description(s)
    [None];[None];N;N;N;[NONE];[NONE];;;;;DefaultParent=#root;English=[None]
    ICT_PERIMETER;EUR;N;N;N;[NONE];[NONE];;;;;DefaultParent=#root;English=PROTEIN Perimeter
    AE01;AED;N;N;N;[NONE];[NONE];K;;;;DefaultParent=ICT_PERIMETER;English=N-FZE
    AE0100;AED;N;Y;N;[NONE];[NONE];K;;;;DefaultParent=AE01;English=N-FZE

    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)
    Else
       WScript.Echo "No input filename specified."
       WScript.Quit
    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)
    Else
       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."
       Wscript.Quit
    End If

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

    ' 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, ";")


    Next

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



    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