i have the following code which walks through an Excel file and this works fine
Please note that the following line does work well (folder is being set earlier in the code)
Console.WriteLine("Value found in {1}: {0} ", Obj.Text, folder)
the whole
For Each xlWorkSheet In xlWorkBook.Worksheets
For rCnt As Integer = 2 To xlWorkSheet.UsedRange.Rows.Count 'we start at 2 becuase we do not need the first header row
For cCnt As Integer = 1 To xlWorkSheet.UsedRange.Columns.Count
Dim Obj As Range = CType(xlWorkSheet.UsedRange.Cells(rCnt, cCnt), Range)
Console.WriteLine("Value found in {1}: {0} ", Obj.Text, folder)
Next
RaiseEvent ImportChanged()
Next
Next
But I would like to fill a dictionary with the items, but the moment I do that it complains it “not being an instance of an object” even if I cast it to Cstr() or use .toString
Anyone knows why?
Dim EntryDetails As Dictionary(Of String, String)
For Each xlWorkSheet In xlWorkBook.Worksheets
For rCnt As Integer = 2 To xlWorkSheet.UsedRange.Rows.Count 'we start at 2 becuase we do not need the first header row
For cCnt As Integer = 1 To xlWorkSheet.UsedRange.Columns.Count
Dim Obj As Range = CType(xlWorkSheet.UsedRange.Cells(rCnt, cCnt), Range)
Console.WriteLine("Value found in {1}: {0} ", Obj.Text, folder)
EntryDetails.Add("demo", Obj.Text) ' THIS DOESNT WORK
EntryDetails.Add("demo", Obj.Text.ToString) ' THIS DOESNT WORK
EntryDetails.Add("demo", CStr(Obj.Text)) ' THIS DOESNT WORK
Next
RaiseEvent ImportChanged()
Next
Next
You haven’t created an actual instance of
EntryDetailsAdd the
Newkeyword to the first line so that the constructor is called: