Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem with ref and out parameters

problem with ref and out parameters

Scheduled Pinned Locked Moved C#
helpcomtutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dominick ODierno
    wrote on last edited by
    #1

    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?

    M 1 Reply Last reply
    0
    • D Dominick ODierno

      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?

      M Offline
      M Offline
      Marcos Accioly
      wrote on last edited by
      #2

      Aren't you missing the "out" modifier in the calling function? []'s Vini

      D 1 Reply Last reply
      0
      • M Marcos Accioly

        Aren't you missing the "out" modifier in the calling function? []'s Vini

        D Offline
        D Offline
        Dominick ODierno
        wrote on last edited by
        #3

        Whoops, I'm amazed that I missed that

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups