cin_champ
asked on
Need assistance with multidimensional arrays in VB.net 2010
Dear Expert,
I need assistance with multidimensional arrays.
I’m looping though a CSV file to find 2 rows and fill an array list with each row's matching values .I woud like to put them in the array to be able to write them back into another csv.
Each Spec Row needs to be concatenate with the matching symbol (field) the label row..
My Code:
Dim items As String()
Dim Datalabel(2) As String
Dim arrDataLabels As String = Datalabel(0)
Dim arrData As String = Datalabel(1)
Using dReader As New IO.StreamReader(filePath)
Dim line As String
While dReader.Peek >= 0
line = dReader.ReadLine
If line.Contains("Spec") Then
dReader.ReadLine
items = line.Split(",".ToCharArray ())
'ReDim Preserve arrDataLabels(0, items.Length())
For count = 0 To items.Length() - 1
‘ Getting error here ¿ 'Chars' is 'ReadOnly'.
--> arrDataLabels(0) = items(count).ToString
count += 1
Next count
End If
If line.Contains("(%)") Then
dReader.ReadLine()
items = line.Split(",".ToCharArray ())
' ReDim Preserve arrDataLabels2(items.Lengt h())
For count = 0 To items.Length() - 1
‘ Getting same error here ¿ 'Chars' is 'ReadOnly'.
and here----> arrData(1) = items(count).ToString
count += 1
Next count
End If
End While
dReader.Close()
End Using
End Function
Can you explain what I'm doing wrong and how I should be inserting the data into my array ?
Thanks!
CJ
I need assistance with multidimensional arrays.
I’m looping though a CSV file to find 2 rows and fill an array list with each row's matching values .I woud like to put them in the array to be able to write them back into another csv.
Each Spec Row needs to be concatenate with the matching symbol (field) the label row..
My Code:
Dim items As String()
Dim Datalabel(2) As String
Dim arrDataLabels As String = Datalabel(0)
Dim arrData As String = Datalabel(1)
Using dReader As New IO.StreamReader(filePath)
Dim line As String
While dReader.Peek >= 0
line = dReader.ReadLine
If line.Contains("Spec") Then
dReader.ReadLine
items = line.Split(",".ToCharArray
'ReDim Preserve arrDataLabels(0, items.Length())
For count = 0 To items.Length() - 1
‘ Getting error here ¿ 'Chars' is 'ReadOnly'.
--> arrDataLabels(0) = items(count).ToString
count += 1
Next count
End If
If line.Contains("(%)") Then
dReader.ReadLine()
items = line.Split(",".ToCharArray
' ReDim Preserve arrDataLabels2(items.Lengt
For count = 0 To items.Length() - 1
‘ Getting same error here ¿ 'Chars' is 'ReadOnly'.
and here----> arrData(1) = items(count).ToString
count += 1
Next count
End If
End While
dReader.Close()
End Using
End Function
Can you explain what I'm doing wrong and how I should be inserting the data into my array ?
Thanks!
CJ
Also
line = dReader.ReadLine
If line.Contains("Spec") Then
dReader.ReadLine
Are you trying to see if line x has Spec and read another line after it?
line = dReader.ReadLine
If line.Contains("Spec") Then
dReader.ReadLine
Are you trying to see if line x has Spec and read another line after it?
ASKER
Thanks for the reply,
I need to loop though a file using datareader .writer. The file is small I'm looping thought the files for first time only to get info for line that contains "Spec" and need to grad all the values on this line and concatenate them with the matching colum value from the next Row that contains (%) .
Row that contains Spec col1 need to be concatenated with the row that contains ((%)) col1(X) + col2 (Y) ...
for as many (COLUMNS) values as there are on those rows...
Any ideas as how I can getthat done?
Cj
I need to loop though a file using datareader .writer. The file is small I'm looping thought the files for first time only to get info for line that contains "Spec" and need to grad all the values on this line and concatenate them with the matching colum value from the next Row that contains (%) .
Row that contains Spec col1 need to be concatenated with the row that contains ((%)) col1(X) + col2 (Y) ...
for as many (COLUMNS) values as there are on those rows...
Any ideas as how I can getthat done?
Cj
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Not a school project just not paying atention when I copied code.
Thanks for your help.
Cj
Thanks for your help.
Cj
Dim arrDataLabels As String = Datalabel(0)
Dim arrData As String = Datalabel(1)
It should be something like
Dim arrDataLabels(10) As String = Datalabel(0)
Dim arrData(10) As String = Datalabel(1)
In other words 10 is the dimensions here. I assume with arr in front these should be actual arrays. What size dimensions you need, I don't know.
I think I'd just use a collection and be done with it. Also why are you splitting to a char array and then trying to stuff that into strings?
Can you show a sample of the input and desired storage and output.
You could make a simple class or structure with fields, with a a constructor that takes the expected values as a string array (from the split), puts each item in a member of the class, and overrides ToString() to produce whatever output you want.
Create a collection
Dim MyCollection As New System.Collections.Generic
And add each item to it if you like.