944,149 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 29536
  • VB.NET RSS
Aug 4th, 2006
0

how to read data from text file into data grid???

Expand Post »
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:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ohohling is offline Offline
7 posts
since Aug 2006
Aug 4th, 2006
0

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:

VB.NET Syntax (Toggle Plain Text)
  1.  
  2.  
  3. 'after you read the line
  4. Dim myArray As Array
  5. 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
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Aug 6th, 2006
0

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/06S1112:483720:E
RX:12/3/06S1113:483721:-E
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ohohling is offline Offline
7 posts
since Aug 2006
Aug 7th, 2006
0

Re: how to read data from text file into data grid???

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

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. 'after you read the line
  3. Dim myArray As Array
  4. myArray = Split(line, ":")

regards
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005
Mar 13th, 2008
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cheehongjb is offline Offline
1 posts
since Mar 2008
Mar 19th, 2008
1

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.

VB.NET Syntax (Toggle Plain Text)
  1. myArray = Split(line, ":")
  2.  
  3. Dim i As Integer
  4. dim val as
  5. For i = 0 To myArray.Length - 1
  6. val = myArray(i) 'read the value of the items in the array
  7. dg.Item(row, column) = val 'place it in the datagrid
  8. Next
Dim myArray As Array

Hope it helps
Reputation Points: 23
Solved Threads: 10
Junior Poster
williamrojas78 is offline Offline
111 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: From InputBox to ListBox??
Next Thread in VB.NET Forum Timeline: syntax Error..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC