473,795 Members | 2,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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/vxlrfvslangproj projectconfigur ationproperties warninglevel.ht m
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
Nov 21 '05 #1
9 2344
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

"harry" <harry@nospam > wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl...
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/vxlrfvslangproj projectconfigur ationpr
opertieswarning level.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

Nov 21 '05 #2
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

"harry" <harry@nospam > wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl...
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/vxlrfvslangproj projectconfigur ationpr
opertieswarning level.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

Nov 21 '05 #3
> Remove the variable. If its never used, why have it in ?,

LOL
Nov 21 '05 #4
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
"harry" <harry@nospam > wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl...
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/vxlrfvslangproj projectconfigur ationproperties warninglevel.ht m
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

Nov 21 '05 #5
> The de facto standard (perhaps because it is free) seems to FxCop, at

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

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
Nov 21 '05 #6
* "harry" <harry@nospam > scripsit:
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/vxlrfvslangproj projectconfigur ationproperties warninglevel.ht m
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

Thank you Charles.
"Charles Law" <bl***@nowhere. com> wrote in message
news:uv******** ******@tk2msftn gp13.phx.gbl...
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
"harry" <harry@nospam > wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl...
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/vxlrfvslangproj projectconfigur ationproperties warninglevel.ht m
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


Nov 21 '05 #8
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

"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
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

"harry" <harry@nospam > wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl...
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/vxlrfvslangproj projectconfigur ationpr
opertieswarning level.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


Nov 21 '05 #9
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

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:Om******** *****@tk2msftng p13.phx.gbl...
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

"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
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

"harry" <harry@nospam > wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl...
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/vxlrfvslangproj projectconfigur ationpr opertieswarning level.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



Nov 21 '05 #10

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

Similar topics

8
5745
by: harry | last post by:
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.
40
7905
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal parameters. For example, a state machine function might take a status input, but a certain error-handling state might ignore it: typedef void (*State_Fn)(uint8_t); void error_state(uint8_t status)
2
2034
by: ~~~ .NET Ed ~~~ | last post by:
It is not the first time I see this happen. I am using VS.NET 2003 with .NET Framework 1.1. In this particular situation I have a custom user control in a windows form. There is a member variable declared with the fully qualified class name (some.namespace.mycontrolclass). Then in the InitializeComponent() it is instantiated and there is a block of code lines that set the various properties of the control class, then further down the usual...
3
3948
by: Pierre | last post by:
Hello, In an aspx page (mypage.aspx) from a web projet, I would like to get the value of a variable of the projet that is declared as public in a module. The variable can be called from anywhere in the code behind page and in the class files, but when I try to call it from an aspx page, it raises an error. <%=myvar%> in mypage.aspx raise an error : the name "myvar" is not declared.
7
14123
by: What-A-Tool | last post by:
In the following code, "catch" is underlined in blue, and the error "the variable fx is declared but never used" is displayed when I mouse hover over it. Am I doing something wrong, or do I just ignore it? private void btnCalc_Click(object sender, System.EventArgs e) {
3
2019
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.