Shorter Declaration when using For Each

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raterus

    Shorter Declaration when using For Each

    Hi, is there a way I can avoid having to declare my variable I use when using a For Each loop?

    Dim adminuser As String 'I'd like to get rid of this line and just declare it all on the next line
    For Each adminuser In adminusers
    If username = adminuser Then
    m_admin = True
    End If
    Next

    Thanks,
    --Michael
  • Gerry O'Brien [MVP]

    #2
    Re: Shorter Declaration when using For Each

    Certainly, .NET now allows you to do this;

    For Each adminuser As String in adminusers
    If username = adminuser Then
    m_admin = True
    End If
    Next


    --
    Gerry O'Brien [MVP]
    Visual Basic .NET


    "Raterus" <moc.liamtoh@su retar.reverse> wrote in message
    news:%23fzmVEcl EHA.3712@TK2MSF TNGP15.phx.gbl. ..
    Hi, is there a way I can avoid having to declare my variable I use when
    using a For Each loop?

    Dim adminuser As String 'I'd like to get rid of this line and
    just declare it all on the next line
    For Each adminuser In adminusers
    If username = adminuser Then
    m_admin = True
    End If
    Next

    Thanks,
    --Michael


    Comment

    • Raterus

      #3
      Re: Shorter Declaration when using For Each

      Oh that's very nice, thank you so much!

      "Gerry O'Brien [MVP]" <gkcomput@hotma il.com> wrote in message news:uWiXsNclEH A.3756@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Certainly, .NET now allows you to do this;
      >
      > For Each adminuser As String in adminusers
      > If username = adminuser Then
      > m_admin = True
      > End If
      > Next
      >
      >
      > --
      > Gerry O'Brien [MVP]
      > Visual Basic .NET
      >
      >
      > "Raterus" <moc.liamtoh@su retar.reverse> wrote in message
      > news:%23fzmVEcl EHA.3712@TK2MSF TNGP15.phx.gbl. ..
      > Hi, is there a way I can avoid having to declare my variable I use when
      > using a For Each loop?
      >
      > Dim adminuser As String 'I'd like to get rid of this line and
      > just declare it all on the next line
      > For Each adminuser In adminusers
      > If username = adminuser Then
      > m_admin = True
      > End If
      > Next
      >
      > Thanks,
      > --Michael
      >
      >[/color]

      Comment

      • Tom Dacon

        #4
        Re: Shorter Declaration when using For Each

        For Each adminuser As String In adminusers
        If username = adminuser Then
        m_admin = True
        End If
        Next

        Tom Dacon
        Dacon Software Consulting

        "Raterus" <moc.liamtoh@su retar.reverse> wrote in message
        news:%23fzmVEcl EHA.3712@TK2MSF TNGP15.phx.gbl. ..
        Hi, is there a way I can avoid having to declare my variable I use when
        using a For Each loop?

        Dim adminuser As String 'I'd like to get rid of this line and
        just declare it all on the next line
        For Each adminuser In adminusers
        If username = adminuser Then
        m_admin = True
        End If
        Next

        Thanks,
        --Michael


        Comment

        • Greg Burns

          #5
          Re: Shorter Declaration when using For Each

          FYI, this was added to NET 1.1 Framework. Or is it just VB 2003 and not
          necessarily the framework...

          Greg

          "Gerry O'Brien [MVP]" <gkcomput@hotma il.com> wrote in message
          news:uWiXsNclEH A.3756@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Certainly, .NET now allows you to do this;
          >
          > For Each adminuser As String in adminusers
          > If username = adminuser Then
          > m_admin = True
          > End If
          > Next
          >
          >
          > --
          > Gerry O'Brien [MVP]
          > Visual Basic .NET
          >
          >
          > "Raterus" <moc.liamtoh@su retar.reverse> wrote in message
          > news:%23fzmVEcl EHA.3712@TK2MSF TNGP15.phx.gbl. ..
          > Hi, is there a way I can avoid having to declare my variable I use when
          > using a For Each loop?
          >
          > Dim adminuser As String 'I'd like to get rid of this line
          > and just declare it all on the next line
          > For Each adminuser In adminusers
          > If username = adminuser Then
          > m_admin = True
          > End If
          > Next
          >
          > Thanks,
          > --Michael
          >[/color]


          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Shorter Declaration when using For Each

            * "Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> scripsit:[color=blue]
            > FYI, this was added to NET 1.1 Framework. Or is it just VB 2003 and not
            > necessarily the framework...[/color]

            It's the VB.NET 2003 programming language...

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

            Comment

            • Cor Ligthert

              #7
              Re: Shorter Declaration when using For Each

              In addition to the others, not making the syntax faster however your program

              \\\
              For Each adminuser As String in adminusers
              If username = adminuser Then
              m_admin = True
              exit For
              End If
              Next
              ///
              I hope this helps?

              :-)

              Cor


              Comment

              • Greg Burns

                #8
                Re: Shorter Declaration when using For Each

                Good catch Cor!

                Greg

                "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
                news:emceJGklEH A.1008@tk2msftn gp13.phx.gbl...[color=blue]
                > In addition to the others, not making the syntax faster however your
                > program
                >
                > \\\
                > For Each adminuser As String in adminusers
                > If username = adminuser Then
                > m_admin = True
                > exit For
                > End If
                > Next
                > ///
                > I hope this helps?
                >
                > :-)
                >
                > Cor
                >
                >[/color]


                Comment

                Working...