Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET Word
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 11:28am
Rate this: bad
good
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.
  Permalink  
Comments
MacRaider4 at 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 at 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 at 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
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Apr 2011
Copyright © CodeProject, 1999-2014
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