473,785 Members | 2,449 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
Jul 21 '05 #1
8 5743
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

Jul 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

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

LOL
Jul 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

Jul 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
Jul 21 '05 #6

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


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


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



Jul 21 '05 #9

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

Similar topics

40
7900
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...
9
2344
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.
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
2018
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
0
9480
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
10325
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
10091
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
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
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...
0
6739
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.