Unused variables that really are?!?

S

Seigfried

There was a previous thread with this title that was closed, so I'm
starting a new one because I have exactly the same problem.

The original poster never did get a satisfactory answer because "the
problem went away as mysteriously as it arrived".

Here's a snippet from my program that illustrates the problem:

Select Case reader.Name
Case "FName"
mySigBlockStruct.FName =
reader.ReadString()
Case "FNameChecked"
Dim I As Integer
I = 1
Dim boolTemp As Boolean
boolTemp =
CBool(reader.ReadString())

In this code, both I and boolTemp are flagged as "Unused Local
Variable". I can move the exact same statements to another part of the
same Sub and they're not flagged anymore.

Anyone have an answer for this?
 
H

Herfried K. Wagner [MVP]

Seigfried said:
The original poster never did get a satisfactory answer because "the
problem went away as mysteriously as it arrived".

Here's a snippet from my program that illustrates the problem:

Select Case reader.Name
Case "FName"
mySigBlockStruct.FName =
reader.ReadString()
Case "FNameChecked"
Dim I As Integer
I = 1
Dim boolTemp As Boolean
boolTemp =
CBool(reader.ReadString())

In this code, both I and boolTemp are flagged as "Unused Local
Variable". I can move the exact same statements to another part of the
same Sub and they're not flagged anymore.

I have experienced this problem from time to time too.

You can try to delete the project's "bin" and "obj" folders and compile it
again, maybe this will fix the problem.
 
S

Stuart Nathan

Are you using VS2005? You don't get that error in 2003.
What is happening is that your are dimension within the select routine
 
G

gene kelley

There was a previous thread with this title that was closed, so I'm
starting a new one because I have exactly the same problem.

The original poster never did get a satisfactory answer because "the
problem went away as mysteriously as it arrived".

Here's a snippet from my program that illustrates the problem:

Select Case reader.Name
Case "FName"
mySigBlockStruct.FName =
reader.ReadString()
Case "FNameChecked"
Dim I As Integer
I = 1
Dim boolTemp As Boolean
boolTemp =
CBool(reader.ReadString())

In this code, both I and boolTemp are flagged as "Unused Local
Variable". I can move the exact same statements to another part of the
same Sub and they're not flagged anymore.

Anyone have an answer for this?

"I" and "boolTemp" as used above only have scope in Case
"FNameChecked". Although they are assigned a value, the variables are
never read by the app in the above 'case', therefore, they are
"unused" or "dead".

Gene
 
S

Seigfried

Thanks for the replies ...

But I don't understand the "Gene Kelley" reply.

Select Case reader.Name
Case "FName"
mySigBlockStruct.FName =
reader.ReadString()
Case "FNameChecked"
Dim I As Integer
I = 1

I may have scope only in this one Case, but it's defined and used in
only this one Case. It still looks like a bug in VB to me.

I was using Visual Basic 2005 Express.
 
I

ImageAnalyst

I think he means that it was assigned but not referenced, that is
nothing else uses the value you assigned to it so the code checker
thinks it's essentially wasted code. Try putting code like
dim j as integer
j = I
after that and see if it now doesn't complain about I anymore. It may
complain about j now, but maybe not about I because I is assigned a
value and something references the value of I.
Just a thought.
 
G

gene kelley

Thanks for the replies ...

But I don't understand the "Gene Kelley" reply.

Select Case reader.Name
Case "FName"
mySigBlockStruct.FName =
reader.ReadString()
Case "FNameChecked"
Dim I As Integer
I = 1

I may have scope only in this one Case, but it's defined and used in
only this one Case. It still looks like a bug in VB to me.

I was using Visual Basic 2005 Express.

Where are they "used"? ("used" meaning the varibles are referenced in
some subsequent code while the varibles still have scope).

This page may be of interest:

http://www.aivosto.com/project/help/problemdetection-deadcode.html

Gene
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top