473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.MainForm

But I cant share subs,

Can I somehow do this with a code file or module?
Jul 17 '06 #1
4 2304
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.MainForm

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.public.dotnet.languages.vb

I hope this gives a starting idea,

Cor
"Daniel N" <sa***********@yahoo.comschreef 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.MainForm

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
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...
3
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...
1
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...
1
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...
5
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...
2
by: key9 | last post by:
Hi all look at the organize tree main.c ------ #include lib_adapter.c main() { foo();
6
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...
1
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...
0
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. ...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...

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.