Variable declarations.... in VB.Net

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

    Variable declarations.... in VB.Net

    In my program I will be using the common structure repeatedly in a module.
    Ex Member.FirstNam e, Member.LastName ..

    How to declare it in one common place, so that I can create an instance of
    this variable and use in sub procedure or function as local variable.

    Currently I am declaring these set of variables in each sub or function.

    VB.Net 2003 and .Net Framework 1.1

    Thank you,

    Pete


  • Michael D. Ober

    #2
    Re: Variable declarations... . in VB.Net

    Put the structure definition in a public module and declare it a public
    structure

    Module Globals
    Public Structure Member
    FirstName as string
    LastName as string
    end structure
    end module

    When you need to use it in a sub or function:

    module (or class) mycode
    sub Main()
    dim m as Member

    m.FirstName = "Mike"
    m.Lastname = "Ober"
    end sub
    end Module (or class)

    Mike Ober.

    "Pete Smith" <PeteSmithAl@ho tmail.com> wrote in message
    news:eIl0PiRKGH A.208@tk2msftng p13.phx.gbl...[color=blue]
    > In my program I will be using the common structure repeatedly in a module.
    > Ex Member.FirstNam e, Member.LastName ..
    >
    > How to declare it in one common place, so that I can create an instance of
    > this variable and use in sub procedure or function as local variable.
    >
    > Currently I am declaring these set of variables in each sub or function.
    >
    > VB.Net 2003 and .Net Framework 1.1
    >
    > Thank you,
    >
    > Pete
    >
    >
    >[/color]



    Comment

    • Dennis

      #3
      RE: Variable declarations... . in VB.Net

      Put the declaration after any "Imports... " declarations and before the class
      declaration. Is should be available in all classes and modules in your
      project, i.e.,

      Imports xxxxxx
      Public Structure myStructure
      FirstName as string
      LastName as string
      End Structure

      Public (or Friend) Class myClass

      .........
      End Class

      --
      Dennis in Houston


      "Pete Smith" wrote:
      [color=blue]
      > In my program I will be using the common structure repeatedly in a module.
      > Ex Member.FirstNam e, Member.LastName ..
      >
      > How to declare it in one common place, so that I can create an instance of
      > this variable and use in sub procedure or function as local variable.
      >
      > Currently I am declaring these set of variables in each sub or function.
      >
      > VB.Net 2003 and .Net Framework 1.1
      >
      > Thank you,
      >
      > Pete
      >
      >
      >[/color]

      Comment

      • m.posseth

        #4
        Re: Variable declarations... . in VB.Net


        in my personal opinion the usage of a module should be avoided ( when
        possible ) so i would go for Dennis`s aproach
        although i would go for a friend scoped declaration unless i explicitly
        want an object to be public ( thus also outside my own assembly )


        regards

        Michel Posseth [MCP]


        "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
        news:A835A6E4-DC35-40FA-9E49-1B97F6157CAF@mi crosoft.com...[color=blue]
        > Put the declaration after any "Imports... " declarations and before the
        > class
        > declaration. Is should be available in all classes and modules in your
        > project, i.e.,
        >
        > Imports xxxxxx
        > Public Structure myStructure
        > FirstName as string
        > LastName as string
        > End Structure
        >
        > Public (or Friend) Class myClass
        >
        > ........
        > End Class
        >
        > --
        > Dennis in Houston
        >
        >
        > "Pete Smith" wrote:
        >[color=green]
        >> In my program I will be using the common structure repeatedly in a
        >> module.
        >> Ex Member.FirstNam e, Member.LastName ..
        >>
        >> How to declare it in one common place, so that I can create an instance
        >> of
        >> this variable and use in sub procedure or function as local variable.
        >>
        >> Currently I am declaring these set of variables in each sub or function.
        >>
        >> VB.Net 2003 and .Net Framework 1.1
        >>
        >> Thank you,
        >>
        >> Pete
        >>
        >>
        >>[/color][/color]


        Comment

        • Michael D. Ober

          #5
          Re: Variable declarations... . in VB.Net

          Sorry, I'm an old VB 6 user and I wrote that off the top of my head.
          Dennis is correct in that the structure should stand on it's own.

          Mike Ober.

          "m.posseth" <michelp@nohaus ystems.nl> wrote in message
          news:%23GLAOFnK GHA.1180@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          >
          > in my personal opinion the usage of a module should be avoided ( when
          > possible ) so i would go for Dennis`s aproach
          > although i would go for a friend scoped declaration unless i explicitly
          > want an object to be public ( thus also outside my own assembly )
          >
          >
          > regards
          >
          > Michel Posseth [MCP]
          >
          >
          > "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
          > news:A835A6E4-DC35-40FA-9E49-1B97F6157CAF@mi crosoft.com...[color=green]
          > > Put the declaration after any "Imports... " declarations and before the
          > > class
          > > declaration. Is should be available in all classes and modules in your
          > > project, i.e.,
          > >
          > > Imports xxxxxx
          > > Public Structure myStructure
          > > FirstName as string
          > > LastName as string
          > > End Structure
          > >
          > > Public (or Friend) Class myClass
          > >
          > > ........
          > > End Class
          > >
          > > --
          > > Dennis in Houston
          > >
          > >
          > > "Pete Smith" wrote:
          > >[color=darkred]
          > >> In my program I will be using the common structure repeatedly in a
          > >> module.
          > >> Ex Member.FirstNam e, Member.LastName ..
          > >>
          > >> How to declare it in one common place, so that I can create an instance
          > >> of
          > >> this variable and use in sub procedure or function as local variable.
          > >>
          > >> Currently I am declaring these set of variables in each sub or[/color][/color][/color]
          function.[color=blue][color=green][color=darkred]
          > >>
          > >> VB.Net 2003 and .Net Framework 1.1
          > >>
          > >> Thank you,
          > >>
          > >> Pete
          > >>
          > >>
          > >>[/color][/color]
          >
          >
          >[/color]



          Comment

          • Pete Smith

            #6
            Re: Variable declarations... . in VB.Net

            Thank you all for your response.
            -Pete


            "Michael D. Ober" <obermd.@.alum. mit.edu.nospam> wrote in message
            news:NUpFf.5223 $5E3.1088@newsr ead1.news.pas.e arthlink.net...[color=blue]
            > Sorry, I'm an old VB 6 user and I wrote that off the top of my head.
            > Dennis is correct in that the structure should stand on it's own.
            >
            > Mike Ober.
            >
            > "m.posseth" <michelp@nohaus ystems.nl> wrote in message
            > news:%23GLAOFnK GHA.1180@TK2MSF TNGP09.phx.gbl. ..[color=green]
            > >
            > > in my personal opinion the usage of a module should be avoided ( when
            > > possible ) so i would go for Dennis`s aproach
            > > although i would go for a friend scoped declaration unless i explicitly
            > > want an object to be public ( thus also outside my own assembly )
            > >
            > >
            > > regards
            > >
            > > Michel Posseth [MCP]
            > >
            > >
            > > "Dennis" <Dennis@discuss ions.microsoft. com> wrote in message
            > > news:A835A6E4-DC35-40FA-9E49-1B97F6157CAF@mi crosoft.com...[color=darkred]
            > > > Put the declaration after any "Imports... " declarations and before the
            > > > class
            > > > declaration. Is should be available in all classes and modules in[/color][/color][/color]
            your[color=blue][color=green][color=darkred]
            > > > project, i.e.,
            > > >
            > > > Imports xxxxxx
            > > > Public Structure myStructure
            > > > FirstName as string
            > > > LastName as string
            > > > End Structure
            > > >
            > > > Public (or Friend) Class myClass
            > > >
            > > > ........
            > > > End Class
            > > >
            > > > --
            > > > Dennis in Houston
            > > >
            > > >
            > > > "Pete Smith" wrote:
            > > >
            > > >> In my program I will be using the common structure repeatedly in a
            > > >> module.
            > > >> Ex Member.FirstNam e, Member.LastName ..
            > > >>
            > > >> How to declare it in one common place, so that I can create an[/color][/color][/color]
            instance[color=blue][color=green][color=darkred]
            > > >> of
            > > >> this variable and use in sub procedure or function as local[/color][/color][/color]
            variable.[color=blue][color=green][color=darkred]
            > > >>
            > > >> Currently I am declaring these set of variables in each sub or[/color][/color]
            > function.[color=green][color=darkred]
            > > >>
            > > >> VB.Net 2003 and .Net Framework 1.1
            > > >>
            > > >> Thank you,
            > > >>
            > > >> Pete
            > > >>
            > > >>
            > > >>[/color]
            > >
            > >
            > >[/color]
            >
            >
            >[/color]


            Comment

            Working...