Ok, I posted earlier this week about reading in data from a csv/txt file into an array. My data is huge, 100 columns and 12000+ rows. I would like to name variables by column and then plot these variables.

After I read the data line by line and delimit the row, I'm not sure how to put each integer into it's own separate column, and then continue this for the next row and the next row, ect.

After some reading I would imagine the proper way to do this would be by creating a structure and then read the data into the structure, but there's no real starter example/tutorial out there that does this. I know some people will read this and get pissy, but you've got to realize I'm coming from Matlab and vb.net is a huge change for me. Any help would be greatly appreciated!!!!!

6 Years
Discussion Span
Last Post by toomuchtodo


I think I may have answered this in your previous question? http://www.daniweb.com/forums/thread296131.html

Anyway read in each line use the split function this will generate an array of a single row take this row and add it to your array.

Note of Caution: if your source file handles empty or null values by skipping them (i.e. instead of putting "1,2,,4" it puts "1,2,4") all bets are off as you will never know what column was skipped.

dim line, rowArr as string
dim Stream as new StreamReader ("MyFile")
dim i, x as integer 

line = Stream.readline 
While line <> "" 'while we have data
	rowArr = line.split(",") 'get array of row values
	if i=0 then 'first time in define the "big" Array
		dim MyArray(x,0) as String 
	end if
	redim preserve MyArray(x,ubound(myArray,2)+1) 'increase upper boundary of second dimension of array by one while preserving entries
	rowArr.CopyTo(MyArray,i) 'copy the row into the "Big" Array at row i
	line = Stream.readline 'read next line
	i=i+1 increease your row counter
End While

Edited by G_Waddell: n/a


Well, I tried again but cant seem to make it happen. I proposed the question to a friend of mine and he did this in VB6 within 5 minutes. Here is the data and VB6 code:

delta_x,delta_y,delta_z,h_x,h_y,h_z,lateral g's,yaw,acceleration,speed

Private Sub Form_Load()
Open App.Path & "\Test_data.csv" For Input As #1

Dim headings() As String
Line Input #1, variables
headings() = Split(variables, ",")
For i = 0 To UBound(headings)
Label1(i).Caption = headings(i)
Do While Not EOF(1)
Line Input #1, variables
headings() = Split(variables, ",")
For i = 0 To UBound(headings)
List1(i).AddItem headings(i)
Close #1
End Sub

I try to convert this over the VB.net but keep getting a "1-D Array of A String Cannot be Converted to A String" error. It's almost like you can't name a line(or a row in my case) easily. I mean in VB6 it was easy, and now it seems like jumping though loop after loop. I can't use VB6 to create my project because I was told explicitly to use .net. So Mr G_Waddell, how could I make convert this over to VB.Net? I'm stumped, and I've researched for hours...any help would be,...well I can't even put it into words how much it would be appreciated!!! Thanks for your feedback thus far!

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.