"variable 'x' declared but never used" warnings in VB.NET

H

harry

Hi,

During compilation, a C# project in my solution triggers the following
warning:

"warning CS0168: The variable 'ex' is declared but never used"

To trigger this warning, it appears the C# compiler WarningLevel needs to be
3 or above.

In the same solution, I also have a VB project, however Help document
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vxlrfvslangprojprojectconfigurationpropertieswarninglevel.htm
says VB maximum WarningLevel is 1.

Is there a workaround? or
Does anyone know of an addin or tool to help me identify declared but unused
variables in my VB.NET code?

Thanks
Harry
 
O

One Handed Man \( OHM - Terry Burns \)

Remove the variable. If its never used, why have it in ?, I note that the
vairable is 'ex', if this is an exception in a try catch block, then either
put some implementation in there to stop the message or remove the try catch
completely as it is serving no purpose.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
S

Shiva

Hi,
Assuming I understood your question correctly: changing the warning level of
a Visual Basic .NET project will not affect C# Project warning level. So,
change the warning level of the C# project to something less than 3 to avoid
this warning.

With respect to the addins to detect unused variables, the tool Total .NET
analyzer (www.fmsinc.com) does that check (in addition to other code
checks).

HTH

Hi,

During compilation, a C# project in my solution triggers the following
warning:

"warning CS0168: The variable 'ex' is declared but never used"

To trigger this warning, it appears the C# compiler WarningLevel needs to be
3 or above.

In the same solution, I also have a VB project, however Help document
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vxlrfvslangprojprojectconfigurationpr
opertieswarninglevel.htm
says VB maximum WarningLevel is 1.

Is there a workaround? or
Does anyone know of an addin or tool to help me identify declared but unused
variables in my VB.NET code?

Thanks
Harry
 
C

Charles Law

Hi Harry

I'm not sure how my colleagues here have come to misunderstand your
question, but for everyone perhaps I can provide my own interpretation:

You have a program containing both C# and VB.NET code. The C# compiler
helpfully tells you of variables that are declared but not used, so that you
can remove them. The VB.NET compiler is not so helpful.

I'm sure you would remove the unused variables, if the compiler would be so
good as to tell you where they are ;-)

The de facto standard (perhaps because it is free) seems to FxCop, at

http://www.gotdotnet.com/team/fxcop/

HTH

Charles
 
N

Nick Malik

The de facto standard (perhaps because it is free) seems to FxCop, at
Hi Charles,

It is freely available, but it is a product in one sense: it has a dedicated
team of individuals within Microsoft who do nothing else but work on this
product. Microsoft isn't just being generous. They use FxCop internally to
perform static analysis of their own code before releasing it to the general
public.

--- N
 
H

Herfried K. Wagner [MVP]

* "harry said:
During compilation, a C# project in my solution triggers the following
warning:

"warning CS0168: The variable 'ex' is declared but never used"

To trigger this warning, it appears the C# compiler WarningLevel needs to be
3 or above.

In the same solution, I also have a VB project, however Help document
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vxlrfvslangprojprojectconfigurationpropertieswarninglevel.htm
says VB maximum WarningLevel is 1.

AFAIK, VB.NET currently doesn't detect these variables. I remember that
there will be a warning in VB 2005.
 
H

harry

Thank you Charles.


Charles Law said:
Hi Harry

I'm not sure how my colleagues here have come to misunderstand your
question, but for everyone perhaps I can provide my own interpretation:

You have a program containing both C# and VB.NET code. The C# compiler
helpfully tells you of variables that are declared but not used, so that
you can remove them. The VB.NET compiler is not so helpful.

I'm sure you would remove the unused variables, if the compiler would be
so good as to tell you where they are ;-)

The de facto standard (perhaps because it is free) seems to FxCop, at

http://www.gotdotnet.com/team/fxcop/

HTH

Charles
 
J

Jay B. Harlow [MVP - Outlook]

OHM,
You can also have just the Catch without a variable defined.

Try
SomethingNew()
Catch
' I really don't want to do any thing here
' Yet I don't want others to know that
' SomethingNew failed
End Try

Hope this helps
Jay
 
O

One Handed Man \( OHM - Terry Burns \)

Do you know, I never tried that construct configuration before, as I have
allways implemented the handling, interesting to know though.

Thanks


OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 

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