Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default philosophical question about programming best practices

Hello all,

I am looking for perspective on VBA (and general programming) methods,
specifically:

In an application I'm writing in VBA, I have multiple forms. These
forms run different utilities, but they share the same drop down
lists, input fields, and cancel buttons, among other things. The forms
are kept separate as different users require different utilities.

Is it good programming practice to utilize the same name and code for
a drop down list of months, for example, which would appear on
multiple forms, or should I just duplicate the code, renaming the
variables?

Pros and cons eagerly sought...

Art
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default philosophical question about programming best practices

c1802362 explained :
Hello all,

I am looking for perspective on VBA (and general programming) methods,
specifically:

In an application I'm writing in VBA, I have multiple forms. These
forms run different utilities, but they share the same drop down
lists, input fields, and cancel buttons, among other things. The forms
are kept separate as different users require different utilities.

Is it good programming practice to utilize the same name and code for
a drop down list of months, for example, which would appear on
multiple forms, or should I just duplicate the code, renaming the
variables?

Pros and cons eagerly sought...

Art


How about using a single userform that shows different 'pages' for the
different utilities. That will obviate the need for duplication of
common controls. In this scenario each 'page' would signify which
'utility mode' the user is in and so the underlying code will handle
processing appropriate for the 'mode'.

The structure of the userform in this case would be like that of a
'wizard', where each page serves a different purpose. I use Frames as
my pages but you could use a MultiPage to do similar. (I find using
Frames easier and can be more compact when needed, plus reduces extra
file 'bulk' and resources overhead from using so many userforms) Page
display is handled by a ShowPage function that takes the index of the
page to display, and (optionally) a list of any 'common' controls to
display that are not outside the page somewhere on the userform. (any
controls common to all pages are on the area outside where the pages
display)

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default philosophical question about programming best practices

On 20/03/2012 23:24, c1802362 wrote:
Hello all,

I am looking for perspective on VBA (and general programming) methods,
specifically:

In an application I'm writing in VBA, I have multiple forms. These
forms run different utilities, but they share the same drop down
lists, input fields, and cancel buttons, among other things. The forms
are kept separate as different users require different utilities.


One way would be to make one form that can hide the bits that some
people don't use and have a hidden configuration settings page.

Is it good programming practice to utilize the same name and code for
a drop down list of months, for example, which would appear on
multiple forms, or should I just duplicate the code, renaming the
variables?


Duplicating code just creates maintenance traps for the future.
If you can write stuff in a way that the whole thing is reusable
elsewhere without any modifications then you should do it that way.

Picking a month is a pretty good example since you can be very sure that
the specification is not going to change at the whim of some PHB.

Pros and cons eagerly sought...

Art


Avoiding unnecessary code duplication is wise. You might also find this
Wiki page on cohesion helpful as a guide to best practice.

http://en.wikipedia.org/wiki/Cohesio...ter_science%29

Too much VBA code that I see has mostly coincidental cohesion.

--
Regards,
Martin Brown
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default philosophical question about programming best practices

Martin/Garry -

I strongly agree with both of your suggestions.

The reason I had been hesitant to have a frame or tab form is that I
wanted to control which users see which utilities - however, your
suggestion to tailor the forms to the user by locking out the uneeded
parts is a great suggestion - I'll start working through that problem

Having only one set of code is always the correct solution. I aspire
to the 'Functional Cohesion' as described in the wikipedia aritcle,
but have been successful only to a point - lots of times, I can reuse
the code almost verbatim, but I may need to tweak one line to achieve
a specific function.

Thanks again

Art
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Practices Question Barb Reinhardt Excel Programming 6 November 28th 07 11:28 PM
Programming question - VB, VBA, C#, C++ Susan Excel Programming 6 May 24th 07 07:03 PM
programming to the vbe question Gary Keramidas Excel Programming 4 August 23rd 06 03:09 PM
best practices question Gary Keramidas Excel Programming 3 March 22nd 06 10:11 AM
Programming question Kelly Excel Programming 1 March 7th 06 04:52 PM


All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"