Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / April 2007

Tip: Looking for answers? Try searching our database.

Variable scope

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 18 Apr 2007 18:57 GMT
I have a class with a variable employeeID as global variable.

I also have a subroutine that uses the same name:

Sub GetEmployee(employeeID as String)

   Get the data
   Assign the Global variables.

End sub

I want to assign the Global variable to the local variable.  Is there a way
to do this easily without changing the name.  I know there is a way to
reference the global variable but I can't remember what it is.

Thanks,

Tom
Mattias Sjögren - 18 Apr 2007 19:48 GMT
>I have a class with a variable employeeID as global variable.

There are no truly global variables in VB.NET. I assume you mean a
field declared at the class level.

>I also have a subroutine that uses the same name:
>
[quoted text clipped - 8 lines]
>to do this easily without changing the name.  I know there is a way to
>reference the global variable but I can't remember what it is.

Just prefix it with  Me (or MyClass)

Me.employeeID = employeeID

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

tshad - 24 Apr 2007 02:17 GMT
That was what I was looking for.

Thanks,

Tom

>>I have a class with a variable employeeID as global variable.
>
[quoted text clipped - 20 lines]
>
> Mattias
Phill W. - 20 Apr 2007 12:06 GMT
> I have a class with a variable employeeID as global variable.

I /really/ hope you don't /mean/ global.

The whole point of a Class is that it "encapsulates" (i.e contains) data
that is relevant to a particular /instance/ of itself.
For example:

Class Employee
   Friend Sub New( ByVal Id as Integer )
      _Id = Id
   End Sub

   Public ReadOnly Property Id() as Integer
      Get
         Return _Id
      End Get
   End Property

   Private _Id as Integer
End Class

...then...

Dim fred as New Employee( 55 )

> I want to assign the Global variable to the local variable.  

If you want to pass a value into a Class, use a Property.

   . . .
   Public Property DepartmentId() as Integer
      Get
         Return _DepartmentId
      End Get
      Set( ByVal DepartmentId as Integer )
         _DepartmentId = DepartmentId
      End Get
   End Property
   Private _DepartmentId as Integer
   . . .

HTH,
   Phill  W.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.