Unused variables that really are?!?

Z

zacks

Suddenly, in a VB2005 project I am working on, several variables show
up in the list of warnings are being unused local variables. But they
all are. Several of them are the ex variable used in a Try/Catch, and
the Catch for each one references the ex exception variable. Yet it is
still flagged as unused? What gives?
 
M

Marina

Are you referencing the exception variable in the catch block? I am guessing
not, which is why it is flagged that awy.
 
H

Herfried K. Wagner [MVP]

Suddenly, in a VB2005 project I am working on, several variables show
up in the list of warnings are being unused local variables. But they
all are. Several of them are the ex variable used in a Try/Catch, and
the Catch for each one references the ex exception variable. Yet it is
still flagged as unused? What gives?

I'm not able to repro the problem you describe with the final version of VS
2005. Which veryion are you using? Does the problem even occur in a newly
created project? Could you post the code you are using? Maybe deleting the
project's "bin" and "obj" folders and recompiling solves the problem.
 
C

Cor Ligthert [MVP]

Zacks,

Suddenly, in a VB2005 project I am working on, several variables show
up in the list of warnings are being unused local variables. But they
all are. Several of them are the ex variable used in a Try/Catch, and
the Catch for each one references the ex exception variable. Yet it is
still flagged as unused? What gives?
It is a new feature what some of us by instance (Herfried and I) are not
completly fond of.

(As far as I have seen does it work correct by the way, however it does not
know that you as human know that some situations cannot exist).

Do not try to create constructions as this.

dim mystring as string = "".

This gives only overhead.

Cor
 
M

Marina

Sure you can. It will catch all exceptions.

The following compiles just fine:

Try
Catch
End Try

It is functionally the same as

Try
Catch ex As Exception
End Try
 
Z

zacks

VS 2005 Version 8.0.50727.42

I have not n oticed this situation in a new project. In fact, it just
cropped up today in a project I have been working on for the past
month.

Deleting the bin and obj folders and rebuilding did not help.

Sorry, I can't post any of the code, my company owns it. I can post the
warning the compiler tells me about these variables:

Warning 5 Unused local variable: 'KeyField'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 140 13 Universal Data Mover
Warning 6 Unused local variable: 'OrderBy'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 141 13 Universal Data Mover
Warning 7 Unused local variable: 'DerivedValue'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 143 13 Universal Data Mover
Warning 8 Unused local variable: 'StillAdding'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 148 13 Universal Data Mover
Warning 9 Unused local variable: 'DoUpdate'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 149 13 Universal Data Mover
Warning 10 Unused local variable: 'KeyChanged'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 150 13 Universal Data Mover
Warning 11 Unused local variable: 'VerificationErrors'. C:\Documents
and Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 151 13 Universal Data Mover
Warning 12 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 253 15 Universal Data Mover
Warning 13 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 279 19 Universal Data Mover
Warning 14 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 317 19 Universal Data Mover
Warning 15 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 350 19 Universal Data Mover
Warning 16 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 431 23 Universal Data Mover
Warning 17 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 459 23 Universal Data Mover
Warning 18 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 498 23 Universal Data Mover
Warning 19 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 545 23 Universal Data Mover
Warning 20 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 765 35 Universal Data Mover
Warning 21 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 774 35 Universal Data Mover
Warning 22 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 815 51 Universal Data Mover
Warning 23 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 827 51 Universal Data Mover
Warning 24 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 935 51 Universal Data Mover
Warning 25 Unused local variable: 'ex'. C:\Documents and
Settings\zacks\My Documents\CIS\SourceSafe Working\Universal Data
Mover\Universal Data Mover\Data_Engine.vb 946 51 Universal Data Mover

In EACH case, the variable flagged as not sure is most definitely used.
 
Z

zacks

How do I get rid of the warnings?

How can one do:

dim mystring as string = ""

without the overhead you mention?
 
Z

zacks

I know you can. It's just that every time I use a Try/Catch is because
I want to know what the error is.
 
H

Herfried K. Wagner [MVP]

How do I get rid of the warnings?

How can one do:

dim mystring as string = ""

without the overhead you mention?

\\\
Dim s As String = Nothing
///

However, I tend to disable the warning as it doesn't make much sense to me.
 
T

tomb

How do I get rid of the warnings?

How can one do:

dim mystring as string = ""

without the overhead you mention?
It's only a warning, kind of like those overkill message the newer
versions of Word give you. It's MS's way of being helpful. But since
they aren't errors, and you are sure there is nothing going on that you
aren't already intending, then just ignore the warnings as meaningless.

Tom
 
J

Jay B. Harlow [MVP - Outlook]

Zacks,
I've noticed this in one of my projects that I converted from VS 2003,
however I could not isolate the cause, nor am I able to reproduce the
problem.

About the only unique thing I noticed is that I had numerous other errors &
warnings in the project. Plus I was experiencing severe RAM cram on that
machine, as it was a substantial multi-project solution where each project
was itself fairly large.



--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Suddenly, in a VB2005 project I am working on, several variables show
| up in the list of warnings are being unused local variables. But they
| all are. Several of them are the ex variable used in a Try/Catch, and
| the Catch for each one references the ex exception variable. Yet it is
| still flagged as unused? What gives?
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top