473,395 Members | 1,456 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,395 software developers and data experts.

Variable does not exist - but does?

Using VS 2005:

Here is a piece of code that is saying that a variable doesn't exist which
obviously does:

public string UpdateTables(TableFieldList tableFields,
UnmappedNamesCollection unmappedNames, DataView dv)
{
bool newSection = false;
bool parameterExists = false; <---- Here is defined
foreignKeys = new ForeignKeyCollection();

using (conn = new SqlConnection(ConnectString))
{
try
{
conn.Open();

foreach (TableField tf in tableFields)
{
parameterExists = false; <--------
Error
....

The error is:

The name 'parameterExists' does not exist in the current context

How can that be?

It is global for the function so how can that error be there?

Is the "using" causing a problem?

Or am I just having a brain fade here?

Thanks,

Tom
Jun 1 '08 #1
3 7078
On Sun, 01 Jun 2008 16:33:37 -0700, tshad <ts***@dslextreme.comwrote:
[...]
The error is:

The name 'parameterExists' does not exist in the current context

How can that be?
Surely the fraction of code that you posted is not exactly the same as the
code actually suffering the error.

If you can post a concise-but-complete code sample that demonstrates the
error, it's probably possible to point out the problem. Otherwise, I
don't think so.

If I had to guess, I'd guess typo somewhere, either in the declaration or
the use. Much less likely (but still possible) is the possibility that
you're coding in Unicode and managed to get a typographically aliased
character into the variable name. Suffice to say, if the name as used was
actually exactly the same as the name as declared, and the structure of
the code was exactly as you've posted here, you wouldn't be getting the
compiler error.

Pete
Jun 1 '08 #2
I did not find any problem in the given piece of code. However since you are
having a compile-time error, I can reduce the area of investigation by
assuring you that "using" construct does not change the scope or life of a
variable. It is similar to other language structures as foreach or while
loop. Thus if you could paste the complete code, probably we could help you
better.
--
Tariq Abdul Karim

http://tariqkarim.blogspot.com/
"tshad" wrote:
Using VS 2005:

Here is a piece of code that is saying that a variable doesn't exist which
obviously does:

public string UpdateTables(TableFieldList tableFields,
UnmappedNamesCollection unmappedNames, DataView dv)
{
bool newSection = false;
bool parameterExists = false; <---- Here is defined
foreignKeys = new ForeignKeyCollection();

using (conn = new SqlConnection(ConnectString))
{
try
{
conn.Open();

foreach (TableField tf in tableFields)
{
parameterExists = false; <--------
Error
....

The error is:

The name 'parameterExists' does not exist in the current context

How can that be?

It is global for the function so how can that error be there?

Is the "using" causing a problem?

Or am I just having a brain fade here?

Thanks,

Tom
Jun 2 '08 #3
"Tariq Abdul Karim" <Ta*************@discussions.microsoft.comwrote in
message news:2A**********************************@microsof t.com...
>I did not find any problem in the given piece of code. However since you
are
having a compile-time error, I can reduce the area of investigation by
assuring you that "using" construct does not change the scope or life of a
variable. It is similar to other language structures as foreach or while
loop. Thus if you could paste the complete code, probably we could help
you
better.
Well, it is working now and I don't know why.

I did comment it out to get it to build, which it did and when I came back
to copy it to paste in the code here, I uncommented it and it worked fine.

So I don't know what was causing it, but it works now.

Thanks,

Tom
--
Tariq Abdul Karim

http://tariqkarim.blogspot.com/
"tshad" wrote:
>Using VS 2005:

Here is a piece of code that is saying that a variable doesn't exist
which
obviously does:

public string UpdateTables(TableFieldList tableFields,
UnmappedNamesCollection unmappedNames, DataView dv)
{
bool newSection = false;
bool parameterExists = false; <---- Here is
defined
foreignKeys = new ForeignKeyCollection();

using (conn = new SqlConnection(ConnectString))
{
try
{
conn.Open();

foreach (TableField tf in tableFields)
{
parameterExists = false; <--------
Error
....

The error is:

The name 'parameterExists' does not exist in the current context

How can that be?

It is global for the function so how can that error be there?

Is the "using" causing a problem?

Or am I just having a brain fade here?

Thanks,

Tom

Jun 2 '08 #4

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

Similar topics

15
by: | last post by:
Hi, I want to do things this way: I have a bunch of stuff that I want to keep track of while a user is connected to the site. Maybe 50 little peices of information. So I know I can make 50...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
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...
6
by: Vmusic | last post by:
Hi, I am using Javascript to add rows to tables, etc. in a function I am calling. I pass the function the ID of the div, and what I want in the rows, and it will add rows to a table in the div. ...
10
by: ben | last post by:
is there anyway in c to write code that can variably make use of one of two structs (one that has 32 bit vals and the other that has 64 bit vals) throughout the code? i'm writing some code that...
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...
3
by: tshad | last post by:
Using VS 2005: Here is a piece of code that is saying that a variable doesn't exist which obviously does: public string UpdateTables(TableFieldList tableFields, UnmappedNamesCollection...
3
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup =...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.