Misreported "Unused Local Variables" Warnings in Visual Studio 2010

  • Thread starter Thread starter BobRoyAce
  • Start date Start date
B

BobRoyAce

I have a project that I'm working on in Visual Studio 2010. There are
62 Warnings shown for the project right now. Many of the warnings are
for supposed unused variables. The weird thing about this is that the
variables are not unused. They are very much used. Here's an example:

Dim oForm As New MaintCALegalExpenseForm
oForm.AddEditMode = gci_ADD_EDIT_MODE_EDIT

Dim oOriginalLegalExpense As CALegalExpense =
gvLegalExcpenses.GetFocusedRow
Dim oNewLegalExpense As New CALegalExpense
oNewLegalExpense = oOriginalLegalExpense.CloneMe(True)

oForm.CurrentLegalExpense = oNewLegalExpense

If (oForm.ShowDialog = DialogResult.OK) Then

_TheCA.LegalExpenses.ReplaceCALegalExpense(oForm.CurrentLegalExpense)
End If

Visual Studio tells me that the variable oForm, declared in the first
line of code above, is an unused local variable. Is this a known issue
with VS 2010 or am I missing something?
 
Am 17.05.2011 07:32, schrieb BobRoyAce:
I have a project that I'm working on in Visual Studio 2010. There are
62 Warnings shown for the project right now. Many of the warnings are
for supposed unused variables. The weird thing about this is that the
variables are not unused. They are very much used. Here's an example:

Dim oForm As New MaintCALegalExpenseForm
oForm.AddEditMode = gci_ADD_EDIT_MODE_EDIT

Dim oOriginalLegalExpense As CALegalExpense =
gvLegalExcpenses.GetFocusedRow
Dim oNewLegalExpense As New CALegalExpense
oNewLegalExpense = oOriginalLegalExpense.CloneMe(True)

oForm.CurrentLegalExpense = oNewLegalExpense

If (oForm.ShowDialog = DialogResult.OK) Then

_TheCA.LegalExpenses.ReplaceCALegalExpense(oForm.CurrentLegalExpense)
End If

Visual Studio tells me that the variable oForm, declared in the first
line of code above, is an unused local variable. Is this a known issue
with VS 2010 or am I missing something?

Just a feedback:
I've tried to reproduce the problem (replaced the unknown data types by known ones)
but I can't. I don't get a warning in this case. (also not in VB 2008)

Have a look here if it's a known issue:
https://connect.microsoft.com/VisualStudio/feedback
 
Hi Bom,

Like Armin I don't see any unused variables in this code.

Although sometimes one misplaced continuation character can cause this.

However, are you already known with the "using" keyword and the property
initializers.

\\\
Dim oOriginalLegalExpense As CALegalExpense = gvLegalExcpenses.GetFocusedRow
Dim oNewLegalExpense As New CALegalExpense
oNewLegalExpense = oOriginalLegalExpense.CloneMe(True)
Using oForm As New MaintCALegalExpenseForm With {
.AddEditMode = gci_ADD_EDIT_MODE_EDIT,
.CurrentLegalExpense = oNewLegalExpense}
oForm.CurrentLegalExpense = oNewLegalExpense
If oForm.ShowDialog = DialogResult.OK Then
_TheCA.LegalExpenses.ReplaceCALegalExpense(oForm.CurrentLegalExpense)
End If
End Using
///
The using takes care of the correct disposing of your modal form while the
property initializer is just an easy way to make maintain better.

Success

Cor


"BobRoyAce" wrote in message

I have a project that I'm working on in Visual Studio 2010. There are
62 Warnings shown for the project right now. Many of the warnings are
for supposed unused variables. The weird thing about this is that the
variables are not unused. They are very much used. Here's an example:

Dim oForm As New MaintCALegalExpenseForm
oForm.AddEditMode = gci_ADD_EDIT_MODE_EDIT

Dim oOriginalLegalExpense As CALegalExpense =
gvLegalExcpenses.GetFocusedRow
Dim oNewLegalExpense As New CALegalExpense
oNewLegalExpense = oOriginalLegalExpense.CloneMe(True)

oForm.CurrentLegalExpense = oNewLegalExpense

If (oForm.ShowDialog = DialogResult.OK) Then

_TheCA.LegalExpenses.ReplaceCALegalExpense(oForm.CurrentLegalExpense)
End If

Visual Studio tells me that the variable oForm, declared in the first
line of code above, is an unused local variable. Is this a known issue
with VS 2010 or am I missing something?
 
Back
Top