0

I'm fairly inexperienced with arrays, but I have a CSV file and I want to grab a specific piece of data from it. For example, I understand how to iterate through the data from the 2nd column, but how do I grab the data 3 rows down in that column? How can I modify this to achieve it? I can't find anything on Google, so I'm wondering if I'm asking the wrong question...

dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile("C:\CSVfile.csv")

Do while NOT objTextFile.AtEndOfStream
  arrStr = split(objTextFile.ReadLine,",")
'strUser = arrStr(0)
strFullName = arrStr(1)
'wscript.echo strUser
wscript.echo strFullName
Loop

objTextFile.Close
set objTextFile = Nothing
set fs = Nothing

For example, if my csv looked like this:

userID, fullname, address 
a1, Tom Green, 123 Apple St 
a2, Chad Mendez, 456 Book Ave 
a3, Ville Valo, 789 Cat Way

How would I grab the data "Chad Mendez"?

TIA!

1 Answer 1

2

Ok, came up with this and it seems to work. So easy, it's dumb - I was overthinking it:

dim fs,objTextFile
set fs=CreateObject("Scripting.FileSystemObject")
dim arrStr
set objTextFile = fs.OpenTextFile("C:\CSV.csv")

rownumber = 1

Do while NOT objTextFile.AtEndOfStream

  arrStr = split(objTextFile.ReadLine,",")
'strUser = arrStr(0)
strFullName = arrStr(1)
'wscript.echo strUser
'wscript.echo strFullName

if rownumber = 3 then

name = strFullName

wscript.echo name

end if

rownumber = rownumber + 1

Loop

objTextFile.Close
set objTextFile = Nothing
set fs = Nothing
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.