Home>

Read by specifying the CSV column with VBScript
I would like to create a VBScript that outputs to a text file
I don't know what to start with.
I would appreciate any advice.

+ +
From the data.csv below
I want to extract the name column, height column, and weight column and output them to result.txt.
Also, at that time, I want to make the comma a half-width space.
↓ data.csv

ID, name, address, number, height, weight
001, suzuki, 1-1,111,170,80
002, tanaka, 1-2,112,180,80
003, naito, 11-3,113,179,66


From
↓ I want to create result.txt.

name height weight
suzuki 170 80
tanaka 180 80
naito 179 66

I tried to google with "vbs csv column specification" etc.
I couldn't get a result that seemed to be a hint.
I would appreciate any advice.

  • Answer # 1

    In the first place, it is impossible to "read by specifying a column", so read all the rows and extract only the necessary columns.

    To split a string with commassplitUse a function.
    cols = split (data, ",")

  • Answer # 2

    There are other answers, but you can't read by specifying a column.
    Aim for the following processing flow.

    Open CSV file

    Open output file

    Loop start

    Read one line of CSV file

    Exit the loop if the CSV file is EOF

    One line read is divided by commas and arranged

    Create a string for output by collecting the required columns

    Write the output string to the output file

    Back to 3

    Close CSV file

    Close output file

    I think you have all the keywords you need, so if you don't understand, please find out for yourself.