Search code examples
vb.netvisual-studio-2012compiler-warningsunused-variables

Unused Local Variables (Visual Studio 2012)


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?


Solution

  • 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!