Using sub in other forms

Annorax

Member
Joined
Aug 31, 2007
Messages
12
Location
MA, USA
Programming Experience
1-3
Hi everyone,

I have more of a general newbie question: what is good coding practice for commonly used code? I am experienced in Java and there I know it's good to make a class with a bunch of methods to be used in many places instead of writing the method in each place. Is there a similar concept or structure in VB.net?

Thanks for any help. :)
 
You can access 'subs' from another form if its declared as 'Public'

For classes, you might want to search the net.
In VB.NET, forms are classes.
I am experienced in Java and there I know it's good to make a class with a bunch of methods to be used in many places instead of writing the method in each place. Is there a similar concept or structure in VB.net?
You should do the same thing in V.NET as in all OOP languages.
Note that if the methods don't access any instance variables from any objects, they can be declared shared. Shared methods can be called without creating an instance of the class.

Search for Vb.NET shared methods for more information.
 
Another interesting addition VB.NET has over Java are the properties which allow you to create accessors and use them like a field. Look for the property keyword.

VB.NET also supports enums (Java supports a very advanced enum model since version 5 only).

However, if you know java, you should be more interested in C# which has anonymous methods that will make event handling look just like event listeners in Java. Along with the event handling part, you may like to look into delegates which are like pointers to methods. That means an event holds a reference to all the objects than contain the event handlers that listen to that event and prevents them from being garbage collected... Event handlers do not actually use inheritance like in java so the event handler can be a method in a very large object.

A last one that comes to mind, you can use methods on value types and literals without any worry, so 3.ToString() will actually work.
 
Back
Top