473,503 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

good practice for VB code

Hi group,

I have a couple of projects with up to 8 forms.
On most projects I write the code on each form with no modules.
The last project I use 1 module and minimal code on each form , in fact just the
code for each visual object, and all the subroutines are placed in a module.

What is the best practice where I can place my VB code, at each form or in a
separate module ?
Pro's & con's ? Performance benefit ?

Tnx

--
Erik De Keyser - Belgium
Jul 17 '05 #1
3 3776
Simple solution...
* Routines used more than once, or by more
than one form, dump em into a module.
* Routines used once, leave it in the form that uses it.

"Erik De Keyser" <ed*@hotmail.com.invalid> wrote in message
news:3f**********************@news.skynet.be...
Hi group,

I have a couple of projects with up to 8 forms.
On most projects I write the code on each form with no modules.
The last project I use 1 module and minimal code on each form , in fact just the code for each visual object, and all the subroutines are placed in a module.
What is the best practice where I can place my VB code, at each form or in a separate module ?
Pro's & con's ? Performance benefit ?

Tnx

--
Erik De Keyser - Belgium

Jul 17 '05 #2
On Fri, 9 Jan 2004 15:05:33 -0600, "CajunCoiler
\(http://www.cajuncoiler.tk\)" <po**********@totallyspamless.cox.net>
wrote:
Simple solution...
* Routines used more than once, or by more
than one form, dump em into a module.
* Routines used once, leave it in the form that uses it.


Yup

And 'mundane' stuff dealing with Controls
- into UserControls (not OCXes) included in the Project
Jul 17 '05 #3
Erik De Keyser wrote:
What is the best practice where I can place my VB code, at each form or in a
separate module ?
Pro's & con's ? Performance benefit ?


Everything that belongs to a specific task can generally be grouped in
one or more class modules. This has the advantage of reusability and
testability: You can have more instances of the same functionality and
you can write unit tests before writing the actual implementation.
You could compare this with the way a modern audio device like a radio
is built: there are separate "classes" for amplification, recieving,
etc. These components may or may not be made by the manufacturer
himself, and can easily be replaced and tested without the rest of the
device.

Try to make your (class) modules as independent as possible from the
rest of your code, as this will make it easier to reuse them in other
projects.

What is left in the forms is the "driving" of the classes that are your
actual application. When you follow this model, you have created a
separate User Interface layer and an application layer. Especially
Microsoft likes you to do that, so that you can easily transform or
expand your application into a web application.

One final word: to be honest, there is no universal good design for all
applications. For some applications, a multi-layer design can be by far
the best option, for others it can be an absurd overkill to a simple
problem. Do not be afraid to let the design of an application evolve.
When you have unit tests, you can refactor the design whenever you need
to. I can recommend the book "Refactoring - Improving the Design of
Existing Code" by Martin Fowler if you want to read more about
controlled adaptation of a software design.
I think the design must fit both the software and the programmer. When
you are feeling you are doing the same trick every day, you will
probably be ready to move general pieces of code into their own (class)
modules and use them in other applications as well. This may be an
obvious improvement in the design, but if you had seen your colleague
doing that when you first started to learn to program, you had probably
seen this as unnecessarily complicated.

Just don't be afraid to improve your own code and you'll grow into an
acceptible good practice.

Best regards

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
3544
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works,...
1
1764
by: trebor | last post by:
I'm learning dotNet, although I first learned programming back in the days when structured programming was all the rage. In both my books and courses, I've seen something like this: Public Class...
150
6320
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and...
54
3583
by: sam.s.kong | last post by:
Hi! I've been programming ASP for 5 years and am now learning PHP. In ASP, you can use GetRows function which returns 2 by 2 array of Recordset. Actually, it's a recommended way in ASP when you...
66
3654
by: KimmoA | last post by:
Hey! Some questions about C that have been bugging me for a while... 1) Is inline a valid C keyword or not? I was kind of surprised of not finding it in C, to be honest. My "The C Programming...
8
7495
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
6
2543
by: MLH | last post by:
I have frmMainMenu with the following two code lines invoked on a button click... 2420 DoCmd.OpenForm "frmVehicleEntryForm", A_NORMAL, , , A_ADD, A_NORMAL 2440 DoCmd.GoToRecord , , A_NEWREC ...
206
8168
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
23
3113
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.