Comma Delimited Files

To write a record to a comma delimited file we insert commas between the data elements of the record

ojbWriter.WriteLine(strId & "," & strName & "," & strStreet & "," & strCity & "," & decGross  )

 

To read a set of data elements (a record) delimited by commas we first input the entire record in a string and then parse the string into separate fields using the Split method of the String class

 

The String Split method

 

Dim strFields(4) as string

:
:

Do Until objFileIn.Peek = -1

strCurInfo = objFileIn.ReadLine()

strFields = strCurInfo.Split(",".ToCharArray)

 

If you know the layout of the record you will know which piece of data is in what position of the record

 

strId = strFields(0)
strName = strFields(1)
strStreet =strFields(2)
strCity = strFields(3)

 

if an input value is a number you convert it to a numeric value

 

decYTDGross = Convert.ToDecimal(strFields(4))