8

I'm ridding my code of all compiler warnings, as per my bosses request, when I came across some unused local variables. Naturally, I removed the ones which were legitimate, however I stumbled upon a couple which aren't as straight forward. (Variable names changed for security)

Dim strAAA As String = "aaaa" & strBBB & Now.ToString("yyyyMMddHHmmss") & ".doc"
If FUNCTION_NAME(strCCCC, strAAA) Then Return True

strAAA is allegedly an 'unused local variable' when it is clearly used directly below.

Even when I write it as follows:

Dim strAAA As String 
strAAA = "ViewLet" & strBBB & Now.ToString("yyyyMMddHHmmss") & ".doc"
If FUNCTION_NAME(strTmpFileName, strAAA) Then Return True

The warning is still present.

Can anybody solve this mystery?

Alex
  • 4,821
  • 16
  • 65
  • 106
Steve Borland
  • 360
  • 3
  • 12
  • 2
    Have you tried ["turning it off and on again"](https://www.youtube.com/watch?v=nn2FB1P_Mn8)? – Steven Doggart Apr 02 '14 at 13:42
  • Probably there's some other error somewhere that is generating what you're seeying. Without seeing the complete code/and error message I doubt anyone will be able to help. – bastos.sergio Apr 02 '14 at 13:43
  • 1
    I've found that if it is compiled with the warning active then later change it, the warning stays until it is re-compiled. – tinstaafl Apr 02 '14 at 13:44
  • @StevenDoggart - First thing I tried (after the obvious) – Steve Borland Apr 02 '14 at 14:03
  • @bastos.sergio - All errors have been eradicated, leaving only this and other unused local variable warnings. This one is the first in the list. – Steve Borland Apr 02 '14 at 14:05
  • @tinstaafl - I tried changing the unused local variable option to 'none', recompiling, setting back to warning and recompiling to no avail. – Steve Borland Apr 02 '14 at 14:06
  • 1
    Have you tried a Clean and then a Rebuild? If that doesn't work, try deleting your bin and obj folders and then build it again. – Steven Doggart Apr 02 '14 at 14:08

2 Answers2

11

Solved it. There was a Return True about 50 lines above. This was always being hit, thus the variables were never being set.

Sloppy code from my predecessor I'm afraid!

Steve Borland
  • 360
  • 3
  • 12
  • 1
    Insult to injury: The blasted function wasn't even getting called! – Steve Borland Apr 02 '14 at 15:28
  • Re: "function wasn't even getting called" - you might be interested in using [FxCop](http://www.microsoft.com/en-us/download/details.aspx?id=6544) to have a check over your code. Or your version of VS might have the code analysis tools built in. – Andrew Morton Apr 02 '14 at 16:00
0

Try eliminating the variable instance...

If FUNCTION_NAME(strTmpFileName, "ViewLet" & strBBB & Now.ToString("yyyyMMddHHmmss") & ".doc") Then Return True
bastos.sergio
  • 6,684
  • 4
  • 26
  • 36