Unused variables that really are?!?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zacks@construction-imaging.com

    Unused variables that really are?!?

    Suddenly, in a VB2005 project I am working on, several variables show
    up in the list of warnings are being unused local variables. But they
    all are. Several of them are the ex variable used in a Try/Catch, and
    the Catch for each one references the ex exception variable. Yet it is
    still flagged as unused? What gives?

  • Marina

    #2
    Re: Unused variables that really are?!?

    Are you referencing the exception variable in the catch block? I am guessing
    not, which is why it is flagged that awy.

    <zacks@construc tion-imaging.com> wrote in message
    news:1134407264 .778295.125380@ g49g2000cwa.goo glegroups.com.. .[color=blue]
    > Suddenly, in a VB2005 project I am working on, several variables show
    > up in the list of warnings are being unused local variables. But they
    > all are. Several of them are the ex variable used in a Try/Catch, and
    > the Catch for each one references the ex exception variable. Yet it is
    > still flagged as unused? What gives?
    >[/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Unused variables that really are?!?

      <zacks@construc tion-imaging.com> schrieb:[color=blue]
      > Suddenly, in a VB2005 project I am working on, several variables show
      > up in the list of warnings are being unused local variables. But they
      > all are. Several of them are the ex variable used in a Try/Catch, and
      > the Catch for each one references the ex exception variable. Yet it is
      > still flagged as unused? What gives?[/color]

      I'm not able to repro the problem you describe with the final version of VS
      2005. Which veryion are you using? Does the problem even occur in a newly
      created project? Could you post the code you are using? Maybe deleting the
      project's "bin" and "obj" folders and recompiling solves the problem.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Unused variables that really are?!?

        Zacks,

        [color=blue]
        > Suddenly, in a VB2005 project I am working on, several variables show
        > up in the list of warnings are being unused local variables. But they
        > all are. Several of them are the ex variable used in a Try/Catch, and
        > the Catch for each one references the ex exception variable. Yet it is
        > still flagged as unused? What gives?
        >[/color]
        It is a new feature what some of us by instance (Herfried and I) are not
        completly fond of.

        (As far as I have seen does it work correct by the way, however it does not
        know that you as human know that some situations cannot exist).

        Do not try to create constructions as this.

        dim mystring as string = "".

        This gives only overhead.

        Cor


        Comment

        • zacks@construction-imaging.com

          #5
          Re: Unused variables that really are?!?

          I would not even have a Catch block if I did not reference the
          exception variable.

          Comment

          • Marina

            #6
            Re: Unused variables that really are?!?

            Sure you can. It will catch all exceptions.

            The following compiles just fine:

            Try
            Catch
            End Try

            It is functionally the same as

            Try
            Catch ex As Exception
            End Try

            <zacks@construc tion-imaging.com> wrote in message
            news:1134412562 .074657.126210@ g49g2000cwa.goo glegroups.com.. .[color=blue]
            >I would not even have a Catch block if I did not reference the
            > exception variable.
            >[/color]


            Comment

            • zacks@construction-imaging.com

              #7
              Re: Unused variables that really are?!?

              VS 2005 Version 8.0.50727.42

              I have not n oticed this situation in a new project. In fact, it just
              cropped up today in a project I have been working on for the past
              month.

              Deleting the bin and obj folders and rebuilding did not help.

              Sorry, I can't post any of the code, my company owns it. I can post the
              warning the compiler tells me about these variables:

              Warning 5 Unused local variable: 'KeyField'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 140 13 Universal Data Mover
              Warning 6 Unused local variable: 'OrderBy'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 141 13 Universal Data Mover
              Warning 7 Unused local variable: 'DerivedValue'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 143 13 Universal Data Mover
              Warning 8 Unused local variable: 'StillAdding'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 148 13 Universal Data Mover
              Warning 9 Unused local variable: 'DoUpdate'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 149 13 Universal Data Mover
              Warning 10 Unused local variable: 'KeyChanged'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 150 13 Universal Data Mover
              Warning 11 Unused local variable: 'VerificationEr rors'. C:\Documents
              and Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 151 13 Universal Data Mover
              Warning 12 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 253 15 Universal Data Mover
              Warning 13 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 279 19 Universal Data Mover
              Warning 14 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 317 19 Universal Data Mover
              Warning 15 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 350 19 Universal Data Mover
              Warning 16 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 431 23 Universal Data Mover
              Warning 17 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 459 23 Universal Data Mover
              Warning 18 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 498 23 Universal Data Mover
              Warning 19 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 545 23 Universal Data Mover
              Warning 20 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 765 35 Universal Data Mover
              Warning 21 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 774 35 Universal Data Mover
              Warning 22 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 815 51 Universal Data Mover
              Warning 23 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 827 51 Universal Data Mover
              Warning 24 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 935 51 Universal Data Mover
              Warning 25 Unused local variable: 'ex'. C:\Documents and
              Settings\zacks\ My Documents\CIS\S ourceSafe Working\Univers al Data
              Mover\Universal Data Mover\Data_Engi ne.vb 946 51 Universal Data Mover

              In EACH case, the variable flagged as not sure is most definitely used.

              Comment

              • zacks@construction-imaging.com

                #8
                Re: Unused variables that really are?!?

                How do I get rid of the warnings?

                How can one do:

                dim mystring as string = ""

                without the overhead you mention?

                Comment

                • zacks@construction-imaging.com

                  #9
                  Re: Unused variables that really are?!?

                  I know you can. It's just that every time I use a Try/Catch is because
                  I want to know what the error is.

                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Unused variables that really are?!?

                    <zacks@construc tion-imaging.com> schrieb:[color=blue]
                    > How do I get rid of the warnings?
                    >
                    > How can one do:
                    >
                    > dim mystring as string = ""
                    >
                    > without the overhead you mention?[/color]

                    \\\
                    Dim s As String = Nothing
                    ///

                    However, I tend to disable the warning as it doesn't make much sense to me.

                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://classicvb.org/petition/>

                    Comment

                    • tomb

                      #11
                      Re: Unused variables that really are?!?

                      zacks@construct ion-imaging.com wrote:
                      [color=blue]
                      >How do I get rid of the warnings?
                      >
                      >How can one do:
                      >
                      >dim mystring as string = ""
                      >
                      >without the overhead you mention?
                      >
                      >
                      >[/color]
                      It's only a warning, kind of like those overkill message the newer
                      versions of Word give you. It's MS's way of being helpful. But since
                      they aren't errors, and you are sure there is nothing going on that you
                      aren't already intending, then just ignore the warnings as meaningless.

                      Tom


                      Comment

                      • Jay B. Harlow [MVP - Outlook]

                        #12
                        Re: Unused variables that really are?!?

                        Zacks,
                        I've noticed this in one of my projects that I converted from VS 2003,
                        however I could not isolate the cause, nor am I able to reproduce the
                        problem.

                        About the only unique thing I noticed is that I had numerous other errors &
                        warnings in the project. Plus I was experiencing severe RAM cram on that
                        machine, as it was a substantial multi-project solution where each project
                        was itself fairly large.



                        --
                        Hope this helps
                        Jay [MVP - Outlook]
                        ..NET Application Architect, Enthusiast, & Evangelist
                        T.S. Bradley - http://www.tsbradley.net


                        <zacks@construc tion-imaging.com> wrote in message
                        news:1134407264 .778295.125380@ g49g2000cwa.goo glegroups.com.. .
                        | Suddenly, in a VB2005 project I am working on, several variables show
                        | up in the list of warnings are being unused local variables. But they
                        | all are. Several of them are the ex variable used in a Try/Catch, and
                        | the Catch for each one references the ex exception variable. Yet it is
                        | still flagged as unused? What gives?
                        |


                        Comment

                        • zacks@construction-imaging.com

                          #13
                          Re: Unused variables that really are?!?

                          This problem actually went away as suddenly and mysteriously as it
                          appeared.

                          Comment

                          Working...