problem with ref and out parameters
-
I am attempting to write a function with the following declaration: void OpenExcel(string filename, out Excel.ApplicationClass XLApp, out Excel.Workbook XLWorkBook, out Excel.Sheets XLSheets, out Excel.Worksheet XLWorkSheet) where the function will open an instance of excel and the workbook with the given filename, and assign the application instance, the workbook, the worksheets collection and the default worksheet to the variables passed in respectively When I attempt to compile I receive the following errors: Argument '2': cannot convert from 'Microsoft.Office.Interop.Excel.Application' to 'out Microsoft.Office.Interop.Excel.ApplicationClass' Argument '3': cannot convert from 'Microsoft.Office.Interop.Excel.Workbook' to 'out Microsoft.Office.Interop.Excel.Workbook' Argument '4': cannot convert from 'Microsoft.Office.Interop.Excel.Sheets' to 'out Microsoft.Office.Interop.Excel.Worksheets' Argument '5': cannot convert from 'Microsoft.Office.Interop.Excel.Worksheet' to 'out Microsoft.Office.Interop.Excel.Worksheet' This also fails when I replace "out" with "ref" Anyone know how to fix this?
-
I am attempting to write a function with the following declaration: void OpenExcel(string filename, out Excel.ApplicationClass XLApp, out Excel.Workbook XLWorkBook, out Excel.Sheets XLSheets, out Excel.Worksheet XLWorkSheet) where the function will open an instance of excel and the workbook with the given filename, and assign the application instance, the workbook, the worksheets collection and the default worksheet to the variables passed in respectively When I attempt to compile I receive the following errors: Argument '2': cannot convert from 'Microsoft.Office.Interop.Excel.Application' to 'out Microsoft.Office.Interop.Excel.ApplicationClass' Argument '3': cannot convert from 'Microsoft.Office.Interop.Excel.Workbook' to 'out Microsoft.Office.Interop.Excel.Workbook' Argument '4': cannot convert from 'Microsoft.Office.Interop.Excel.Sheets' to 'out Microsoft.Office.Interop.Excel.Worksheets' Argument '5': cannot convert from 'Microsoft.Office.Interop.Excel.Worksheet' to 'out Microsoft.Office.Interop.Excel.Worksheet' This also fails when I replace "out" with "ref" Anyone know how to fix this?
Aren't you missing the "out" modifier in the calling function? []'s Vini
-
Aren't you missing the "out" modifier in the calling function? []'s Vini
Whoops, I'm amazed that I missed that