Click here to Skip to main content
15,887,989 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,

I recently converted my vb6 project to VB.NET.

I get an error when I build that says....

Unused local variable

If you know the solution to this issue, please post it here

Thank you.
Posted
Updated 31-May-11 2:28am
v2
Comments
Sandeep Mewara 31-May-11 9:54am    
These kind of questions does not help. You need to put in effort in trying the issue and presenting the same here.
thatraja 31-May-11 13:41pm    
I'm sure it's not error, just a warning.
Rob Branaghan 1-Jun-11 4:10am    
Yeah it would just be a warning. :)

Never leave unused variables in the code. Just remove them.

Also, remember: if you collect warnings in your code, you will not be able to use warning mechanism at all. Develop warning-free!

—SA
 
Share this answer
 
You can solve this by locating the variable by double clicking the error line in the error pane in Visual Studio, and then just remove that variable.

Then rebuild.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-May-11 15:49pm    
Correct, my 5.
Please see my answer as, too.
--SA
What's so hard to understand? You declared a variable, then you didn't use it. It's not going to stop your code from running. It's just a warning.
 
Share this answer
 
I'm had this problem, but I most definitely was using the variables, a lot.
- Solved
This procedure started as a stub, and I had left the Return call at the top before my variable declarations. The variables weren't being used, as code execution never even reached their declaration. Good catch, developer studio!
 
Share this answer
 
v2
Comments
tigerwood2006 12-Nov-15 17:35pm    
this is the correct answer
When you get this Warning all you need to do is to initialize the variable when you create it.

VB
Private myString As String = Nothing


My apologies for giving a misleading answer. I was completely confused with another issue I was experiencing where a Warning is issued saying that a variable is used before it was declared. Not sure why I thought it had anything to do with this question.

So for the down votes, thank you much appreciated however it would have been grand not to just down vote it but to also give a reason why and show the err in my way.
 
Share this answer
 
v2
Comments
[no name] 12-Aug-14 18:29pm    
Most likely for the reason that the question was asked and answered over 3 years ago and answering ancient already answered questions serves no purpose.
Tino Fourie 13-Aug-14 1:18am    
Posted 3 days ago
somethinginnovative279
Edited 3 days ago v2

Well Solution 4 was posted 3 days before and since it appeared on the 2nd page of the Quick Answers list I did not bother to look at the date when the OP posted the question.

I think it is only fair to say that this reply of yours should apply to Solution 4 AND since the Quick Answers list does not show the date when it was originally posted I assume that it was a recent question.

As much I have ignored the date of the original post, you did not bother to check why it happened. And if you were one of the down voters, your reason for down voting is really poor and without substance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900