Micro Focus QTP (UFT) Forums
How to update CSV File and need to Save same CSV File - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: How to update CSV File and need to Save same CSV File (/Thread-How-to-update-CSV-File-and-need-to-Save-same-CSV-File)



How to update CSV File and need to Save same CSV File - kotaramamohana - 10-21-2015

Hi Team,

I want to update CSV file by modifying some data based on column. In Row 2 or 3. And need to save same CSV File. Can you please help me in same


RE: How to update CSV File and need to Save same CSV File - tigerliew - 10-24-2015

try codes below:

Code:
Set inFile  = objFSO.OpenTextFile("test.csv")
Set outFile = objFSO.OpenTextFile("test2.csv.tmp", 2, True)
dim iRowCount
iRowCount =0
Do while not objTextFile.AtEndOfStream
 line = inFile.ReadLine
 iRowCount = iRowCount + 1
 if iRowCount=2 then
    arrStr = Split(line, ",")
    If arrStr(0) = strFirm Then
      soNumber = CInt(arrStr(1))
      outFile.WriteLine arrStr(0) & "," & (soNumber + 1)
    Else
     outFile.WriteLine line
   End If
 elseif iRowcount>2 then
     exit do
 end if
Loop

inFile.Close
outFile.Close