Reading CSV file with different data types

TomV

New member
Joined
Nov 19, 2007
Messages
3
Programming Experience
Beginner
In a nutshell need to read in data , line by line, from a CSV file, manipulate some of the data, which has different data types (characters, integers), and then write the file to disk.

What I have done is use the SPLIT function which reads the data in fine BUT converts all the data to a String type which causes a problem as not all the data is meant to be a string type.

For example this line causes an error:
If Fieldsval(575 + d) = 1 And Fieldsval(585 + d) = 1 Then Fieldsval(855 + d) = Fieldsval(855 + d) + 1

This throws a compiler error: 1 dimensional array of string cannot be converted to 1 dimensional array of variant type because string isn't derived from a variant type.

Tried converting the data from a string to a variantType array but the compiler throws an error that the string can't be converted to a variant because its not derived from a variant Type

Is it possible to easily read a CSV file that has different data types on the same line into a variant or other type array ?

I'm very new to programming in general and vb.net specifically

Any help or suggestions are appreciated
 
This is wrong:
What I have done is use the SPLIT function which reads the data in fine BUT converts all the data to a String type which causes a problem as not all the data is meant to be a string type.
It's not converted to a string because it's a string already. A CSV file contains nothing but text, so if you're storing numbers or dates or whatever in that file then you're storing string representations of those values. It's up to you to convert those values from strings into the appropriate types.

If you want to convert a String to an Integer then use Convert.ToInt32. If you want to convert a String to a Date then use Convert.ToDate. Etc., etc.
 
Back
Top