Last post Sep 12, 2016 06:25 AM by Nan Yu
Sep 10, 2016 01:03 PM|sg48asp|LINK
Warning; In the line near the end
p.Executive(dsData, filePath, SheetNameArray)
I get a warning that sheet name array is being passed by reference before it has been assigned a value.
How do i eliminate the warning?
Protected Sub ImportExcel(sender As Object, e As EventArgs)
Dim SheetCount As Integer
Dim SheetNameArray() As String
Dim p As New Procedures
'Open the Excel file in Read Mode using OpenXml.
Using doc As SpreadsheetDocument = SpreadsheetDocument.Open(filePath, False)
Dim sheets As Sheets = doc.WorkbookPart.Workbook.Sheets
SheetCount = 1 'Added bySG
For Each sheet As Sheet In sheets
SheetCount += 1 'added
ReDim Preserve SheetNameArray(SheetCount)
SheetNameArray(SheetCount) = sheet.Name Next
'IRRELEVANT CODE DELETED
p.Executive(dsData, filePath, SheetNameArray) 'Stubbed Out
Sep 12, 2016 06:25 AM|Nan Yu|LINK
The error is clear ,if you know the array size , you could try declare and instantiate arrays like :
Dim SheetNameArray(5) As String
If you are going to use a collection that you don't know the size of in advance, there are better options than arrays. You could use a List<string> instead - it will allow you to add as many items as you need .