Click here to Skip to main content
13,090,299 members (76,103 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Before I spend time trying to do this I'd like to get a second opinion. I'm writing an application and in it I need to open a word doc in about 4 different places (as of now). So instead of writing the same code 4 times I'm thinking a class would be the way to go? I'm thinking pass the file name to the class and process as normal (all of the error handling is taken care of in the loops right now). Does this sound feasible?
Posted 26-Apr-11 10:28am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Writing reusable code rather than cut & paste the same thing over and over again is a good design and what you should strive for in all your software.
MacRaider4 26-Apr-11 16:35pm
That's what I figured, and using the word object in a seperate class won't cause any issues right? Just have to do all the usual declerations and what not...
NuttingCDEF 26-Apr-11 16:36pm
Agreed - and might add some stuff in to your class to handle the Word App object intelligently so that you aren't forever starting up / shutting down Word (and killing your app's performance in the process).
MacRaider4 26-Apr-11 16:43pm
Actually I have a lot of that already in there, thus the reason I didn't want to have it in so many locations. So far easier than I thought it would be (still getting used to using classes), only took about 5 min to implement in 2 locations.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Whether it is feasible depends on how well your code works. But in general, yes, you should not have to repeat the same code in multiple places. Even twice is too many. So extracting a class/static method that does this would certainly be an improvement.

In a UI scenario, you mght even want to have a custom control that accepts a word document path and renders it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 26 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100