473,626 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Organize Code

I am new to .net and want to organize my code better. I am writing in vb.net
and the code for my main form is nearing 50-60 pages and would like to
create another file like a class, module or code file that SHARE sub
procedures, and declarations as if it were with the rest of the code (So I
can orginize it in 2 or 3 .vb files).

When I create a new class I can;

Inherits Project.MainFor m

But I cant share subs,

Can I somehow do this with a code file or module?
Jul 17 '06 #1
4 2325
V
Hello Daniel,

If its just code-organization that you are looking at and if you are
using 2.0 version of Dot Net, then you may want to read up on Partial
Classes. This feature allows you to break up one class into many files,
thus helping the organization of the code better. I typically have a
separate file for public methods, a separate one for properties, and a
separate one for private methods and member variables.

Also, if your classes are getting SO bog, then you may want to refactor
by making new classes.

- Vaibhav
Daniel N wrote:
I am new to .net and want to organize my code better. I am writing in vb.net
and the code for my main form is nearing 50-60 pages and would like to
create another file like a class, module or code file that SHARE sub
procedures, and declarations as if it were with the rest of the code (So I
can orginize it in 2 or 3 .vb files).

When I create a new class I can;

Inherits Project.MainFor m

But I cant share subs,

Can I somehow do this with a code file or module?
Jul 17 '06 #2
"Daniel N" <sa***********@ yahoo.comwrote
>I am new to .net and want to organize my code better. I am writing in
vb.net and the code for my main form is nearing 50-60 pages [...]
It's time for some software engineering. Stop slinging code, take a step
back, and design your solution.

You need business entities of some sort, be they factories, class entities,
or typed datasets. Seperate your presentation tier from your business logic,
and from your data tier.

This isn't a language or a coding issue, but a design issue. There's no
language feature that going to solve your problem, not partial classes, not
generics, not anonymous methods. Fire up Visio, and start doing some UML
diagrams...

--
Chris Mullins
http://www.coversant.net/blogs/cmullins
Jul 17 '06 #3
Daniel,

VB is OOP now, that means exactly that you don't share things as it was done
in modulair programming.

You create Objects as you need them. Therefore you make classes (templates)

If you need such an object you can say.

Dim myObject as New MyClass

You can use that myObject now in your method.

(I reallise me, that this is a very short way of telling it).

A to this dedicated newsgroup in VB is the newsgroup
microsoft.publi c.dotnet.langua ges.vb

I hope this gives a starting idea,

Cor
"Daniel N" <sa***********@ yahoo.comschree f in bericht
news:RM******** *********@fe08. lga...
>I am new to .net and want to organize my code better. I am writing in
vb.net and the code for my main form is nearing 50-60 pages and would like
to create another file like a class, module or code file that SHARE sub
procedures, and declarations as if it were with the rest of the code (So I
can orginize it in 2 or 3 .vb files).

When I create a new class I can;

Inherits Project.MainFor m

But I cant share subs,

Can I somehow do this with a code file or module?


Jul 17 '06 #4
I am new to .net and want to organize my code better. I am writing in vb.net
and the code for my main form is nearing 50-60 pages and would like to
create another file like a class, module or code file that SHARE sub
procedures, and declarations as if it were with the rest of the code (So I
can orginize it in 2 or 3 .vb files).
...
Can I somehow do this with a code file or module?
Create a new Module file file in your project and add code like below:

Public Module WhateverModule
Public Sub Abcde()
End Sub
End Module

Sub Abcde will be visible (callable) from your form. You can cut/paste subs
and functions from your form vb file to this vb file. If you make them
public, they will be callable from your form.

There are two things that will impede moving a sub into the module. First,
you may have variables declared in your form that are used by a sub, and such
subs are poor candidates for moving to the module. Second, the sub may
reference form properties (eg Show, Hide, etc) in which case you would need
to augment the sub something like this
private sub xxxx(...)
becomes
public sub xxxx(byval MyForm as form,...)
In xxxx, you will have to change Show to MyForm.Show.

The above suggestion directly answers your question, but it is not an OO
suggestion. Other responders have suggested rethinking your program
organization, and I agree. Whether you rethink or not, the technique you
will follow is to create new module and/or class files, cut and paste from
the form into the new file, and tweak the code to make it work. In some
cases, the tweaking will be substantial.

Jul 17 '06 #5

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

Similar topics

10
11065
by: Bruce W...1 | last post by:
I've been learning about PHP for a couple of weeks. With includes, PHP scripts, and HTML I can see where a large and complex website could easily turn in to a big hairy mess with files all over the place. Are there any adopted standards, recognized recommendations, or best practices on how all the code should be organized? I haven't found any websites that discuss this. Can anyone point me to information on this? If not then what do...
3
2277
by: _andrea | last post by:
I'd like to write a web-application with other people. It is the first time I write code together other person. I'd like to ask you some advices: 1)have an advice? 2)wich program to use for VCS (for windows)? 3)how to organize the work? Thank you in advance, Andrea.
1
1928
by: Rudderius | last post by:
Hey, I'm working on a winform app in VS 2005. I'm wondering if someone knows some best practices on how to organize the toolstrips. I have a menuToolStrip and some other toolstrips. As in many apps, the functionality of the toolstrip en the menubar overlap. (e.g. cut & copy etc) The commands I'm using for my application are more complex off course than just a copy and a paste.
1
1122
by: ASP Developer | last post by:
I have a user control with exposed properties. I have about 100 properties. I would like to organize them so they are easier for other programmers to peruse. Is it possible to organize the misc section and add +/- sections to make it easier to read?
5
2593
by: Daniel N | last post by:
I am new to .net and want to organize my code better. I am writing in vb.net 2003 and the code for my main form is nearing 50-60 pages and would like to create another file like a class, module or code file that SHARE sub procedures, and declarations as if it were with the rest of the code (So I can orginize it in 2 or 3 .vb files). When I create a new class I can; Inherits Project.MainForm
2
3525
by: key9 | last post by:
Hi all look at the organize tree main.c ------ #include lib_adapter.c main() { foo();
6
2196
by: Larry Bud | last post by:
Been working with .net 2 since January, and am in the middle of my first large project. It's becoming obvious that one must organize their code well in a large project to make maintenance easier. So what's your process? Do you stick everything in one Class file? Do you have a separate class file for each "type" of function.. i.e. one for all data access, another for general math, another for string function, etc.
1
1888
by: Thomas Wittek | last post by:
Hi! Is there any possibility/tool to automatically organize the imports at the beginning of a module? I don't mean automatic imports like autoimp does as I like seeing where my objects/functions really come from. For the same reason I don't like "from foo import *". The downside is that you have a rather verbose import section at the
0
1155
by: Dudeja, Rajat | last post by:
Hi, I'm learning Python to write a GUI application using Tkinter & Tk. I've evaluated Eclipse and Pydev. With the help of Fabio Zadrozny I successfully installed Eclipse and PyDev. Thanks. Now, I'm learning Eclipse and PyDev. And my problem is that I don't have an understanding of how the code in
2
2476
by: Fredrik Lundh | last post by:
Dudeja, Rajat wrote: A Python program consists of a script file (the py file you run to start the program), and usually one or more additional module files (py files that you import). The latter can be organized in packages, where appropriate. There's also a search path (sys.path) that you can modify in various ways (including from within the program) if you want to fetch modules from different locations.
0
8262
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7192
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.