search a value on .txt file using vbscript-VBForums
Results 1 to 1 of 1

Thread: search a value on .txt file using vbscript

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    1

    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)
    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
    
    
    
    Set objFile = objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
    sLine = objFile.ReadLine
    objFile.Close
    
    '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" 
    				
    				'arrField(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
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.