Re: Confused about OOP programming!
Stacey Levine <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <A48E95FB3D4D02449554AE952F3B3E4702FC43C7@vmcexchng.www.musicforasong.net> |
If it is on the same form, declare a private form level variable to hold the excel object. A form level variable is not the same as a globabl variable. -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Steve Abaffy Sent: Thursday, March 29, 2007 3:41 PM To: [email protected] Subject: [DOTNET-WINFORMS] Confused about OOP programming! It might be that I just don't understand something here, but it seems to me there is a problem. Back in the days it was a big rule to use global variables as little as possible. However this is what I see. On a windows form I have a open file button so in code I have //pseudo code: OpenFileDialogBox GetFileName Create Excel Object Open File Read in Headers Display Headers in Listbox Close Excel File Dispose of Excel Object End button Action Then user selects the headers he/she wishes to work with Select Process File Button In File Button Action //pseudo code: Create Another Excel Object for input Create Excel Object for output Open the same Excel File Read in desired rows based on header selection Process the information Save Output file Close Output file Close Input file Dispose of Both Excel objects. Now the problem I see here is that I am open and closing the same file twice. I can of course get around this problem by using a global InputExcelObj but that seems to violate the do not use global variable rule. What is a better way to do this? And of course if one could use a ExcelObjClass where you can have methods like GetCellValue, SaveFile, OpenFileforRead, OpenFileForWrite etc... that would be even better. (Haven't quite figured that out yet as I can't seem to open a file for Write, a different problem I will work on).