Results 1 to 1 of 1
  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017

    search a value on .txt file using vbscript

    I have a .txt file and i need to search a particular value on it ,
    i need to open read the file , and then search for exemple the value of 'DefCurrency' when 'Label'=AE0100 for this i need to found the row : '!MEMBERS=ENTITY' and then return the value of 'DefCurrency'

    i use the below code to read my file but i can't found how a found the value of DefCurrency:
    HTML Code:
    ' 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
    Set objFile = objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
    sLine = objFile.ReadLine
    'bIsEntity = false
    'arrData = Split(strData, vbCrLf)
    For i = 0 To UBound(arrData)
    	'sLine = objFile.ReadLine
    	aLine = sLine.Split(";")
    	 'arrField = Split(arrData(i), ";")
    	if InStr(1, sLine, "!MEMBERS=ENTITY" , 1)  then
    	'arrField = Split(arrData(i), ";")
    '		bIsEntity = true
    '	elseif bIsEntity = true then
    		if ubound(arrField)>1 then
    			if arrField(3) <> "AllowAdjs" then
    				arrField(3)= "mycurrency" 
    				'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
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.