• VB.net Nazi Problem
    2 replies, posted
[code] Private Sub PopulateDataGridViewFromCSV(ByVal SFileName As String) 'Variables to store the count of rows and columns Dim nRows As Long Dim nCols As Long 'Index variables to retrieve the data row wise and col wise Dim row As Integer Dim col As Integer 'Declaration of Two dimensional array to store the csv content row wise and column wise Dim ParseArray(1, 1) As String 'Use Try Catch block to handle exceptions Try 'Check if file exist If File.Exists(sFileName) Then 'Open the CSV File into stream Dim sr As StreamReader = File.OpenText(sFileName) 'Declaration of two single dimensional arrays to store the individual content Dim RowStringArray() As String Dim ColStringArray() As String 'Load content of file to RowStringArray array RowStringArray = sr.ReadToEnd().Split(Environment.NewLine) 'Retrieve the total number of rows nRows = UBound(RowStringArray) ' Split the content based on "," delimiter ColStringArray = RowStringArray(0).Split(",") 'Retrieve the total number of columns nCols = UBound(ColStringArray) ' Redimension the array. ReDim ParseArray(nRows, nCols) 'Copy the csv content into the 2-dimensional array. For row = 0 To nRows ColStringArray = RowStringArray(row).Split(",") For col = 0 To nCols ParseArray(row, col) = ColStringArray(col) Next Next 'Display the data in ListBox Dim dgRow As DataGridViewRow For row = 0 To nRows For col = 0 To nCols dgRow = new DataGridViewRow() '##########################Problem Line########################## dgRow[col] = ParseArray(row,col) '##########################Problem Line########################## Next 'Add the row dbGridView.Rows.Add(dgRow) Next End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub [/code] Hello Peeps. The code above I am using to convert a CSV into a two dimensional array. This is fine until.. when i come to compile the line between the "# problem line #"'s when it converts it into the following, due to VB.NET being a codenazi [code] dgRow([col] = ParseArray(row,col)) [/code] I can't for the life of me see why it is doing this, and how i can get around it. oh, the error i'm receiving is "Expression is not a method" any help would be appreciated.
so what are you using at the moment, you wrote two versions: [code]dgRow([col] = ParseArray(row,col))[/code] and [code]dgRow[col] = ParseArray(row,col)[/code] anyway, I think VB does arrays with brackets so try: [code]dgRow(col) = ParseArray(row, col)[/code]
the second one is what i was using, but VB.net corrects it to the first one, and then gives an error. There in lies my problem. will try your suggestion right now. update: No luck on the last suggestion. *snip... was bollocks anyway*
Sorry, you need to Log In to post a reply to this thread.