Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read CSV fields in from text file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want to read data elements in from a CSV text file and manipulate each field individually. Right now I only know how to read in the entire line.

How should I read in this text file, then separate each line into separate CSV fields? TIA! -James

TEXTFILE Example
192.168.1.1, HP 4000, Marketing
192.168.1.2, HP 8000, Administration
 
Got it...

'************************************************************
'* FUNCTION: READFILE(strFileName)
'*
'*
'*
'*
'************************************************************

Function ReadFile(strFileName)

Dim oFS, LineArray, Line, strData

Set oFS = CreateObject("Scripting.FileSystemObject")

If oFS.FileExists(strFileName) = True Then

Set File = oFS.OpenTextFile(strFileName)

While Not File.AtEndOfStream
Line=File.ReadLine
LineArray = Split (Line, ",")
WScript.Echo "Line: " & Line

For Each strData In LineArray
WScript.Echo strData
Next

WEnd

File.Close
Set oFS = Nothing

End If

End Function
'************************************************************

ReadFile "c:\test.txt"

***********
C:\TEST.TXT
172.28.19.101, HP 4000, Marketing
198.168.1.1, DeskJet 420, Administration
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top