I recently had to spend some time writing some code that controls Office 2003 from a .NET app. As a curly-brace fan, I started writing the controller code using C#. However, my fingers slowly wore to the bone providing parameters to methods in Word such as PrintOut():
// C#
Object background = Type.Missing;
Object append = Type.Missing;
Object range = Type.Missing;
Object outputFileName = Type.Missing;
Object from = Type.Missing;
Object to = Type.Missing;
Object item = Type.Missing;
Object copies = Type.Missing;
Object pages = Type.Missing;
Object pageType = Type.Missing;
Object printToFile = Type.Missing;
Object collate = Type.Missing;
Object fileName = Type.Missing;
Object activePrinterMacGX = Type.Missing;
Object manualDuplexPrint = Type.Missing;
Object printZoomColumn = Type.Missing;
Object printZoomRow = Type.Missing;
Object printZoomPaperWidth = Type.Missing;
Object printZoomPaperHeight = Type.Missing;
ThisDocument.PrintOut(ref background, ref append,
ref range, ref outputFileName, ref from, ref to,
ref item, ref copies, ref pages, ref pageType,
ref printToFile, ref collate, ref activePrinterMacGX,
ref manualDuplexPrint, ref printZoomColumn, ref printZoomRow,
ref printZoomPaperWidth, ref printZoomPaperHeight);
Doesn’t it make so much more sense to write the following VB.NET code?
ThisDocument.PrintOut().
In short, use the right tool for the job :)
1 archived reader comment
Peter Provost (2003-09-21)
Why not do this? ;)
object missingParam = Type.Missing; ThisDocument.PrintOut( ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam, ref missingParam );
Not really much better, I know but whatcha gonna do.
Seriously, I agree. It would be nice if we could handle optional params better in C#.