On Tue, 14 Dec 2004 08:39:06 -0800, "Kou Vang" <Ko*****@discussions.microsoft.com> wrote:
¤ I have a large text file seperated by commas. I was wondering how to get the
¤ values from the text file. The problem is that not all the characters are
¤ the same length, so I can't use the characters, but is I can't find how to
¤ seperate out the values by the commas. I know that reading the whole line is
¤ possible, but what if I just want the third value and not the rest? Thanks.
¤
¤ exp: 9821,1550,200,2004
You can use ADO.NET and the OLEDB provider to do this:
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "E:\My Documents\TextFiles" & ";" & _
"Extended Properties=""Text;HDR=NO;"""
Dim TextConnection As New System.Data.OleDb.OleDbConnection(ConnectionString )
TextConnection.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM CSV#txt", TextConnection)
Dim ds As New DataSet("TextFiles")
da.Fill(ds, "CSV")
Dim dt As DataTable
dt = ds.Tables("CSV")
DataGrid1.SetDataBinding(ds, "CSV")
Dim drCurrent As DataRow
For Each drCurrent In dt.Rows
'Console.WriteLine(drCurrent.Item(0).ToString)
'Console.WriteLine(drCurrent(1).ToString)
Console.WriteLine(drCurrent(2).ToString)
'Console.WriteLine(drCurrent(3).ToString)
'Console.WriteLine(drCurrent(4).ToString)
'Console.WriteLine(drCurrent(5).ToString)
'Console.WriteLine(drCurrent(6).ToString)
Next
TextConnection.Close()
Paul ~~~
pc******@ameritech.net
Microsoft MVP (Visual Basic)