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!!!!!

Hi,

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 
dim 

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
		x=rowArr.length-1 
		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 6 Years Ago 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
0.1,1,10,0.1,1,10,5,15,25,35
0.2,2,20,0.2,2,20,10,20,30,40
0.3,3,30,0.3,3,30,15,25,35,45
0.4,4,40,0.4,4,40,20,30,40,50
0.5,5,50,0.5,5,50,25,35,45,55
0.6,6,60,0.6,6,60,30,40,50,60
0.7,7,70,0.7,7,70,35,45,55,65
0.8,8,80,0.8,8,80,40,50,60,70
0.9,9,90,0.9,9,90,45,55,65,75
1,10,100,1,10,100,50,60,70,80

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)
Next
Do While Not EOF(1)
Line Input #1, variables
headings() = Split(variables, ",")
For i = 0 To UBound(headings)
List1(i).AddItem headings(i)
Next
Loop
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.