Module or Code file ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

I want to write a program with many sub-method.
for example,
1)method :company_search(code) which return name,addresss...etc
2)method:currency(code) which return the current exchange rate....etc
..... manys

Should I write it use module ??? or in code file ??
What is the difference about it ?
Thanks
From Agnes
 
A module is merely a class so ultimately there's no difference between a
module and a class -- however modules have all of their properties/methods
that are shared. If you create a sealed class, and make all of the
methods/properties shared, you'll be in the same boat. Many things lend
themselves to static methods (File.Exists) others to instances Dim fi as
new FileInfo

It really depends on the ultimate usage. Modules are convenient in that you
don't have to prefix them, but that can also cause some trouble in some
instances b/c a name in your class shares a name w/ the module. You can
kill the variable you have locally or change its name and you won't see any
immediate errors if they were both of the same type (and if you have option
strict off [which should be outlawed], it's possible even then. C# also
doesn't support modules so using the class driven approach may be more
comfortable programming in both environments.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
Hi Agnes,

In addition to Bill, in my opinion is it only good programming to use a
module in a real small application or in a VB6 upgrade project.

In VB.net I use classes. There are two types; the names are so called names.
- The shared class (which contains a lot (mostly all) of shared methods
and properties)
- The non-shared class

From a non-shared class you have to create an object in your programming by
instancing them.
Dim mynewClassObject as New myNonSharedClass.
Dim myvalue = mynewClassObject.value

Shared members, events and properties in a class can directly called by
their name
Dim myvalue = mySharedClass.value

The benefit above a module is that you shall call them instancing or using
their name, with which they become immediately recognizable in your project.

The benefit from a non-shared class above a shared class is that it uses
less memory. It goes out of scope when the procedure ends where it is in
created (which is not true, the truth is when there are no references
anymore to it).

I hope this helps?

Cor
 
* "Agnes said:
I want to write a program with many sub-method.
for example,
1)method :company_search(code) which return name,addresss...etc
2)method:currency(code) which return the current exchange rate....etc
.... manys

Should I write it use module ??? or in code file ??

In addition to the other replies:

Have a look at this chapter in the documentation -- it will provide an
introduction to object oriented programming with VB.NET:

<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconprogrammingwithobjects.asp>
 
Back
Top