Let's see your dirty hacks!
Posted: Sun Dec 01, 2013 8:05 am
here's mine.
When you are programming in VSTO, Microsoft uses a singleton pattern for the current document. In the case of Excel, it is ThisWorkbook. This singleton object is a great place to stuff information that you want to... oh let's call it what it is... its a great place to abuse the singleton pattern to stuff global variables in a language designed not to let you use globals (because globals are bad, evil, poor programmer form).
So I've got this block of code in the Magicus Occultus Excel to Database exporter.
No, I don't need to worry about thread saftey, which is why I felt safe using the simplicity of a global variable.
When you are programming in VSTO, Microsoft uses a singleton pattern for the current document. In the case of Excel, it is ThisWorkbook. This singleton object is a great place to stuff information that you want to... oh let's call it what it is... its a great place to abuse the singleton pattern to stuff global variables in a language designed not to let you use globals (because globals are bad, evil, poor programmer form).
So I've got this block of code in the Magicus Occultus Excel to Database exporter.
Code: Select all
//Hack Alert! We are using global variables as a communication medium here to track the status of exports.
// This is why I'm a product manager now and not a professional programmer any more :)
public int totalRecords = 0; //this global variable is used to report the total number of records in the current export
public int totalSheets = 0; //this global variable is used to report the total number of worksheets in the current export