i need to create a system to read the txt file data to datagrid
but i just know read by line.

that say the sample.txt file pettern as below:

date time price
1/8 2:15pm $5.00
2/8 3:20pm $6.00

how i going to fill the data separate by date, time, and price??
means read by row n column....n fill into datagrid....

if got sample to show then will be more better....:lol:


It looks like you have a set of " " between the columns, so what i would do is split each line one at a time, something like this:

'after you read the line
Dim myArray As Array
myArray = Split(line, "  ")

that will create an array with the data what you want. Probably you will have to trim each line to get rid of the empty spaces.

Hope it helps


if the text file data is seperate by symbol ":" then how i going to do

sample data

Then you split the array when ":" is found.

'after you read the line
Dim myArray As Array
myArray = Split(line, ":")


Dear williamrojas78, ohohling
may i know how to read the data from the array?

after assign the txt line into the array by the code above. how can i take 1 by 1 and put it into datagrid?

thanks a lot


Here it is; first you read the array, then you read line by line and after that you place it in the grid.

myArray = Split(line, ":")

Dim i As Integer
dim val as 
For i = 0 To myArray.Length - 1
     val = myArray(i)                'read the value of the items in the array
     dg.Item(row, column) = val      'place it in the datagrid

Dim myArray As Array

Hope it helps

This article has been dead for over six months. Start a new discussion instead.