Module or Code file ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Agnes

    Module or Code file ?

    I want to write a program with many sub-method.
    for example,
    1)method :company_search (code) which return name,addresss.. .etc
    2)method:curren cy(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


  • William Ryan  eMVP

    #2
    Re: Module or Code file ?

    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




    "Agnes" <agnes@dynamict ech.com.hk> wrote in message
    news:%23mtvxXfR EHA.3344@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > I want to write a program with many sub-method.
    > for example,
    > 1)method :company_search (code) which return name,addresss.. .etc
    > 2)method:curren cy(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
    >
    >[/color]


    Comment

    • Cor Ligthert

      #3
      Re: Module or Code file ?

      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 mynewClassObjec t as New myNonSharedClas s.
      Dim myvalue = mynewClassObjec t.value

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

      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


      Comment

      • Cor Ligthert

        #4
        Re: Module or Code file ?

        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 mynewClassObjec t as New myNonSharedClas s.
        Dim myvalue = mynewClassObjec t.value

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

        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


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Module or Code file ?

          * "Agnes" <agnes@dynamict ech.com.hk> scripsit:[color=blue]
          > I want to write a program with many sub-method.
          > for example,
          > 1)method :company_search (code) which return name,addresss.. .etc
          > 2)method:curren cy(code) which return the current exchange rate....etc
          > .... manys
          >
          > Should I write it use module ??? or in code file ??[/color]

          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/vbconprogrammin gwithobjects.as p>

          --
          Herfried K. Wagner [MVP]
          <URL:http://dotnet.mvps.org/>

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Module or Code file ?

            * "Agnes" <agnes@dynamict ech.com.hk> scripsit:[color=blue]
            > I want to write a program with many sub-method.
            > for example,
            > 1)method :company_search (code) which return name,addresss.. .etc
            > 2)method:curren cy(code) which return the current exchange rate....etc
            > .... manys
            >
            > Should I write it use module ??? or in code file ??[/color]

            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/vbconprogrammin gwithobjects.as p>

            --
            Herfried K. Wagner [MVP]
            <URL:http://dotnet.mvps.org/>

            Comment

            Working...