DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   how to read data from text file into data grid??? (http://www.daniweb.com/forums/thread51743.html)

ohohling Aug 4th, 2006 6:44 am
how to read data from text file into data grid???
 
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....
thanks....

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

williamrojas78 Aug 4th, 2006 6:06 pm
Re: how to read data from text file into data grid???
 
Hi

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

Regards

ohohling Aug 6th, 2006 5:08 am
Re: how to read data from text file into data grid???
 
if the text file data is seperate by symbol ":" then how i going to do

sample data
RX:12/3/06:SS1112:483720:E
RX:12/3/06:SS1113:483721:-E

williamrojas78 Aug 7th, 2006 11:02 am
Re: how to read data from text file into data grid???
 
Then you split the array when ":" is found.


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

regards

cheehongjb Mar 13th, 2008 2:49 am
Re: how to read data from text file into data grid???
 
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

williamrojas78 Mar 19th, 2008 10:01 pm
Re: how to read data from text file into data grid???
 
Hi,

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
Next
Dim myArray As Array

Hope it helps


All times are GMT -4. The time now is 7:49 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC