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.