Home All Groups Group Topic Archive Search About

Unused variables that really are?!?

Author
21 Apr 2006 9:00 PM
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?

Author
21 Apr 2006 10:10 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Seigfried" <Seigfr***@msn.com> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
22 Apr 2006 9:25 PM
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
Author
23 Apr 2006 7:27 AM
gene kelley
Show quote Hide quote
On 21 Apr 2006 14:00:28 -0700, "Seigfried" <Seigfr***@msn.com> wrote:

>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
Author
24 Apr 2006 6:09 PM
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.
Author
25 Apr 2006 3:47 AM
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.
Author
25 Apr 2006 4:19 AM
gene kelley
Show quote Hide quote
On 24 Apr 2006 11:09:43 -0700, "Seigfried" <Seigfr***@msn.com> wrote:

>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