Results 1 to 2 of 2

Thread: [VBS] Change data in columns in CSV

  1. #1
    Join Date
    Apr 2012
    Location
    Europe
    Posts
    7

    [VBS] Change data in columns in CSV

    Hello

    I have data in csv file

    DATE;DEPART;CLASSE;SERVEUR;ERROR;MESSAGE;SCHEDULE;TYP;DUREE;TAILLE(Kb);FICHIERS;RETENTION;WARS Date ouverture;WARS Date fermeture;Commentaires
    2012-04-22;21:01:25;lala_nbondv02_data;nbondv02;0;the req ops;lmejvd-lala-2sem;lalaérentielle;00:12:53;1909225;1447;2 Sem
    2012-04-22;21:00:00;lala_nbondv02_sys;nbondv02;1;the req ops;lmmjvd-lala-2sem;lalaérentielle;00:03:58;371778;2184;2 Sem
    2012-04-22;21:00:59;lala_nbondv03_data;nbondv03;0;OK;lmejvd-lala-2sem;lalaérentielle;00:07:49;892604;6695;2 Sem
    2012-04-22;21:00:00;lala_nbondv03_sys;nbondv03;2;OK;lmmjvd-lala-2sem;lalaérentielle;00:08:38;1209603;399;5 Sem
    2012-04-22;21:00:57;lala_nbondv04_data;nbondv04;0;OK;lmejvd-lala-2sem;lalaérentielle;03:22:41;135497795;300;2 Sem
    I need to split to array, than change 1 or 2 in "column 5" in to 0

    I have code

    Code:
    Function OK()
    
    Const ForReading = 1
    Const ForWriting = 2
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\Rapport.csv", ForReading)
    
    Do
    strLine = objFile.Readline
    tmpArr=Split(strLine, ";")
    If tmpArr(4)="1" or tmpArr(4)="2" Then tmpArr(4)="0" End If
    strNewContents=Join(tmpArr,";")
    Loop
    
    
    Set objFile = objFSO.OpenTextFile("C:\Rapport.csv", ForWriting)
    
    objFile.Write strNewContents
    objFile.Close
    
    End Function
    And I have error:

    Microsoft VBScript runtime error: Input past end of file
    What is wrong with it ?

    Please help

  2. #2
    Join Date
    Nov 2011
    Posts
    342

    Re: [VBS] Change data in columns in CSV

    I have not tried out the same but then i have found few people to be mentioning that they were able to get it work by the below code in the similar sitaution.
    Function OK()

    Const ForReading = 1
    Const ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\2012-04-22.csv", ForReading)

    strNewContents = Replace(objFile.ReadAll, "the requested operation was partially successful", "OK")
    objFile.Close

    Set objFile = objFSO.OpenTextFile("C:\2012-04-22.csv", ForWriting)

    objFile.Write strNewContents
    objFile.Close
    End Function
    Just try it out and see if it is helping.

Similar Threads

  1. how to match data between 2 columns in excel
    By dankar in forum Windows Software
    Replies: 1
    Last Post: 25-04-2013, 11:16 AM
  2. How to divide two different columns data in Excel
    By Chini mao in forum Microsoft Project
    Replies: 1
    Last Post: 08-01-2012, 06:47 PM
  3. How to swap data between columns and rows in Excel
    By Rao's in forum Microsoft Project
    Replies: 1
    Last Post: 08-01-2012, 05:46 PM
  4. How to find percentage of columns data in Excel
    By Kungfu Pandey in forum Windows Software
    Replies: 2
    Last Post: 07-01-2012, 06:20 PM
  5. How can you sort data in columns with Numbers for iPad?
    By Aasha in forum Portable Devices
    Replies: 3
    Last Post: 01-10-2010, 12:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,265,983.19039 seconds with 17 queries