Confused about OOP programming!

Steve Abaffy <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <03cd01c7723a$21182a90$63487fb0$@biz>
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).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.