473,378 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Variable scope

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
Apr 18 '07 #1
3 2233
>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:

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.
Just prefix it with Me (or MyClass)

Me.employeeID = employeeID
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 18 '07 #2
tshad wrote:
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.
Apr 20 '07 #3
That was what I was looking for.

Thanks,

Tom
"Mattias Sjögren" <ma********************@mvps.orgwrote in message
news:eR****************@TK2MSFTNGP05.phx.gbl...
>
>>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:

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.

Just prefix it with Me (or MyClass)

Me.employeeID = employeeID
Mattias

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

Apr 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: YGeek | last post by:
Is there any difference between declaring a variable at the top of a method versus in the code of the method? Is there a performance impact for either choice? What about if the method will return...
3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
2
by: Shraddha | last post by:
Can we declare extern variable as static? What will be the scope of the variable then? What if we change the value of the variable in some other function? Also can someone tell me that if we can...
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
3
by: SRoubtsov | last post by:
Dear all, Do you know whether ANSI C (or some other dialects) support the following: * a variable name coincides with a type name, * a structure/union field name coincides with a type name in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.