Home All Groups Group Topic Archive Search About

Variable declarations.... in VB.Net

Author
3 Feb 2006 11:22 PM
Pete Smith
In my program I will be using the common structure repeatedly in a module.
Ex Member.FirstName, 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

Author
4 Feb 2006 4:46 PM
Michael D. Ober
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.

Show quoteHide quote
"Pete Smith" <PeteSmit***@hotmail.com> wrote in message
news:eIl0PiRKGHA.208@tk2msftngp13.phx.gbl...
> In my program I will be using the common structure repeatedly in a module.
> Ex Member.FirstName, 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
>
>
>
Author
4 Feb 2006 6:44 PM
Dennis
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


Show quoteHide quote
"Pete Smith" wrote:

> In my program I will be using the common structure repeatedly in a module.
> Ex Member.FirstName, 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
>
>
>
Author
5 Feb 2006 4:29 PM
m.posseth
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]


Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:A835A6E4-DC35-40FA-9E49-1B97F6157CAF@microsoft.com...
> 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:
>
>> In my program I will be using the common structure repeatedly in a
>> module.
>> Ex Member.FirstName, 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
>>
>>
>>
Author
5 Feb 2006 4:41 PM
Michael D. Ober
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.

Show quoteHide quote
"m.posseth" <mich***@nohausystems.nl> wrote in message
news:%23GLAOFnKGHA.1180@TK2MSFTNGP09.phx.gbl...
>
> 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" <Den***@discussions.microsoft.com> wrote in message
> news:A835A6E4-DC35-40FA-9E49-1B97F6157CAF@microsoft.com...
> > 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:
> >
> >> In my program I will be using the common structure repeatedly in a
> >> module.
> >> Ex Member.FirstName, 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
> >>
> >>
> >>
>
>
>
Author
7 Feb 2006 1:18 AM
Pete Smith
Thank you all for your response.
-Pete


Show quoteHide quote
"Michael D. Ober" <ober***@.alum.mit.edu.nospam> wrote in message
news:NUpFf.5223$5E3.1088@newsread1.news.pas.earthlink.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" <mich***@nohausystems.nl> wrote in message
> news:%23GLAOFnKGHA.1180@TK2MSFTNGP09.phx.gbl...
> >
> > 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" <Den***@discussions.microsoft.com> wrote in message
> > news:A835A6E4-DC35-40FA-9E49-1B97F6157CAF@microsoft.com...
> > > 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:
> > >
> > >> In my program I will be using the common structure repeatedly in a
> > >> module.
> > >> Ex Member.FirstName, 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
> > >>
> > >>
> > >>
> >
> >
> >
>
>
>