Q: Index for a row

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

    Q: Index for a row

    Hi

    Can anybody help me with the following question?

    Suppose I have the following code, where myTable is already defined
    elsewhere:

    For Each row In myTable.Rows
    ' Get an index for the row
    Next

    Within the loop, I'd like to be able to get hold of the zero based index for
    the row being used. I know that I could simply add a variable before the
    loop and then increment it within the loop, but I think there is an inbuilt
    function to do it e.g. row.GetIndex(), or whatever.

    Can anybody help?

    Geoff



  • Alex Levi

    #2
    RE: Q: Index for a row

    You can use the for statement:

    For i as intgeger = 0 to myTable.items.c ount - 1
    ' [i] - represent the index of each row
    ' [myTable.items.i tem(i)] - represent the item for each row (index)
    Next i




    "Geoff Jones" wrote:
    [color=blue]
    > Hi
    >
    > Can anybody help me with the following question?
    >
    > Suppose I have the following code, where myTable is already defined
    > elsewhere:
    >
    > For Each row In myTable.Rows
    > ' Get an index for the row
    > Next
    >
    > Within the loop, I'd like to be able to get hold of the zero based index for
    > the row being used. I know that I could simply add a variable before the
    > loop and then increment it within the loop, but I think there is an inbuilt
    > function to do it e.g. row.GetIndex(), or whatever.
    >
    > Can anybody help?
    >
    > Geoff
    >
    >
    >
    >[/color]

    Comment

    • David Williams

      #3
      RE: Q: Index for a row

      You can look at the RowNumber property for a cell in the row.

      index = row.Item(0).Row Number

      HTH
      --
      David Williams, VB.NET MVP


      "Geoff Jones" wrote:
      [color=blue]
      > Hi
      >
      > Can anybody help me with the following question?
      >
      > Suppose I have the following code, where myTable is already defined
      > elsewhere:
      >
      > For Each row In myTable.Rows
      > ' Get an index for the row
      > Next
      >
      > Within the loop, I'd like to be able to get hold of the zero based index for
      > the row being used. I know that I could simply add a variable before the
      > loop and then increment it within the loop, but I think there is an inbuilt
      > function to do it e.g. row.GetIndex(), or whatever.
      >
      > Can anybody help?
      >
      > Geoff
      >
      >
      >
      >[/color]

      Comment

      • Geoff Jones

        #4
        Re: Q: Index for a row

        Thanks Alex

        However, it isn't possible to do using For Each then? That is, is there no
        way of working out the index (using inbuilt members) of the row being
        process in the loop?

        Geoff

        "Alex Levi" <AlexLevi@discu ssions.microsof t.com> wrote in message
        news:7A78159A-40CD-4213-977C-CE1F494E5214@mi crosoft.com...[color=blue]
        > You can use the for statement:
        >
        > For i as intgeger = 0 to myTable.items.c ount - 1
        > ' [i] - represent the index of each row
        > ' [myTable.items.i tem(i)] - represent the item for each row (index)
        > Next i
        >
        >
        >
        >
        > "Geoff Jones" wrote:
        >[color=green]
        > > Hi
        > >
        > > Can anybody help me with the following question?
        > >
        > > Suppose I have the following code, where myTable is already defined
        > > elsewhere:
        > >
        > > For Each row In myTable.Rows
        > > ' Get an index for the row
        > > Next
        > >
        > > Within the loop, I'd like to be able to get hold of the zero based index[/color][/color]
        for[color=blue][color=green]
        > > the row being used. I know that I could simply add a variable before the
        > > loop and then increment it within the loop, but I think there is an[/color][/color]
        inbuilt[color=blue][color=green]
        > > function to do it e.g. row.GetIndex(), or whatever.
        > >
        > > Can anybody help?
        > >
        > > Geoff
        > >
        > >
        > >
        > >[/color][/color]


        Comment

        • Cor Ligthert

          #5
          Re: Q: Index for a row

          Hi Geoff,

          You make me curious, why would you want to use it and what is than the
          benefit of that?
          (That for index method very effective in my opinion)

          Cor
          [color=blue]
          > Thanks Alex
          >
          > However, it isn't possible to do using For Each then? That is, is there no
          > way of working out the index (using inbuilt members) of the row being
          > process in the loop?
          >
          > Geoff
          >
          > "Alex Levi" <AlexLevi@discu ssions.microsof t.com> wrote in message
          > news:7A78159A-40CD-4213-977C-CE1F494E5214@mi crosoft.com...[color=green]
          > > You can use the for statement:
          > >
          > > For i as intgeger = 0 to myTable.items.c ount - 1
          > > ' [i] - represent the index of each row
          > > ' [myTable.items.i tem(i)] - represent the item for each row (index)
          > > Next i
          > >
          > >
          > >
          > >
          > > "Geoff Jones" wrote:
          > >[color=darkred]
          > > > Hi
          > > >
          > > > Can anybody help me with the following question?
          > > >
          > > > Suppose I have the following code, where myTable is already defined
          > > > elsewhere:
          > > >
          > > > For Each row In myTable.Rows
          > > > ' Get an index for the row
          > > > Next
          > > >
          > > > Within the loop, I'd like to be able to get hold of the zero based[/color][/color][/color]
          index[color=blue]
          > for[color=green][color=darkred]
          > > > the row being used. I know that I could simply add a variable before[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          > > > loop and then increment it within the loop, but I think there is an[/color][/color]
          > inbuilt[color=green][color=darkred]
          > > > function to do it e.g. row.GetIndex(), or whatever.
          > > >
          > > > Can anybody help?
          > > >
          > > > Geoff
          > > >
          > > >
          > > >
          > > >[/color][/color]
          >
          >[/color]


          Comment

          • Geoff Jones

            #6
            Re: Q: Index for a row

            Hi Cor

            Merely being inquisitive :)

            Geoff

            "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
            news:eDM9Im1YEH A.3304@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Hi Geoff,
            >
            > You make me curious, why would you want to use it and what is than the
            > benefit of that?
            > (That for index method very effective in my opinion)
            >
            > Cor
            >[color=green]
            > > Thanks Alex
            > >
            > > However, it isn't possible to do using For Each then? That is, is there[/color][/color]
            no[color=blue][color=green]
            > > way of working out the index (using inbuilt members) of the row being
            > > process in the loop?
            > >
            > > Geoff
            > >
            > > "Alex Levi" <AlexLevi@discu ssions.microsof t.com> wrote in message
            > > news:7A78159A-40CD-4213-977C-CE1F494E5214@mi crosoft.com...[color=darkred]
            > > > You can use the for statement:
            > > >
            > > > For i as intgeger = 0 to myTable.items.c ount - 1
            > > > ' [i] - represent the index of each row
            > > > ' [myTable.items.i tem(i)] - represent the item for each row[/color][/color][/color]
            (index)[color=blue][color=green][color=darkred]
            > > > Next i
            > > >
            > > >
            > > >
            > > >
            > > > "Geoff Jones" wrote:
            > > >
            > > > > Hi
            > > > >
            > > > > Can anybody help me with the following question?
            > > > >
            > > > > Suppose I have the following code, where myTable is already defined
            > > > > elsewhere:
            > > > >
            > > > > For Each row In myTable.Rows
            > > > > ' Get an index for the row
            > > > > Next
            > > > >
            > > > > Within the loop, I'd like to be able to get hold of the zero based[/color][/color]
            > index[color=green]
            > > for[color=darkred]
            > > > > the row being used. I know that I could simply add a variable before[/color][/color]
            > the[color=green][color=darkred]
            > > > > loop and then increment it within the loop, but I think there is an[/color]
            > > inbuilt[color=darkred]
            > > > > function to do it e.g. row.GetIndex(), or whatever.
            > > > >
            > > > > Can anybody help?
            > > > >
            > > > > Geoff
            > > > >
            > > > >
            > > > >
            > > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Cor Ligthert

              #7
              Re: Q: Index for a row

              Hi David,

              I can not find that, do you have a link on MSDN for that one?

              Cor
              [color=blue]
              > You can look at the RowNumber property for a cell in the row.
              >
              > index = row.Item(0).Row Number
              >
              > HTH
              > --
              > David Williams, VB.NET MVP
              >
              >
              > "Geoff Jones" wrote:
              >[color=green]
              > > Hi
              > >
              > > Can anybody help me with the following question?
              > >
              > > Suppose I have the following code, where myTable is already defined
              > > elsewhere:
              > >
              > > For Each row In myTable.Rows
              > > ' Get an index for the row
              > > Next
              > >
              > > Within the loop, I'd like to be able to get hold of the zero based index[/color][/color]
              for[color=blue][color=green]
              > > the row being used. I know that I could simply add a variable before the
              > > loop and then increment it within the loop, but I think there is an[/color][/color]
              inbuilt[color=blue][color=green]
              > > function to do it e.g. row.GetIndex(), or whatever.
              > >
              > > Can anybody help?
              > >
              > > Geoff
              > >
              > >
              > >
              > >[/color][/color]


              Comment

              • Samuel L Matzen

                #8
                Re: Q: Index for a row

                David,

                I can't seem to get your solution to work. Can you point me to some
                documentation on the RowNumber method of the Item object of a row?

                -Sam Matzen


                "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in message
                news:BDACA264-ECB3-461A-AB8F-4EFB87910AC5@mi crosoft.com...[color=blue]
                > You can look at the RowNumber property for a cell in the row.
                >
                > index = row.Item(0).Row Number
                >
                > HTH
                > --
                > David Williams, VB.NET MVP
                >
                >
                > "Geoff Jones" wrote:
                >[color=green]
                > > Hi
                > >
                > > Can anybody help me with the following question?
                > >
                > > Suppose I have the following code, where myTable is already defined
                > > elsewhere:
                > >
                > > For Each row In myTable.Rows
                > > ' Get an index for the row
                > > Next
                > >
                > > Within the loop, I'd like to be able to get hold of the zero based index[/color][/color]
                for[color=blue][color=green]
                > > the row being used. I know that I could simply add a variable before the
                > > loop and then increment it within the loop, but I think there is an[/color][/color]
                inbuilt[color=blue][color=green]
                > > function to do it e.g. row.GetIndex(), or whatever.
                > >
                > > Can anybody help?
                > >
                > > Geoff
                > >
                > >
                > >
                > >[/color][/color]


                Comment

                • Geoff Jones

                  #9
                  Re: Q: Index for a row

                  I think David was using a member of a DataGrid; which wasn't the case I was
                  dealing with. Good try though!

                  Geoff

                  "Samuel L Matzen" <smatzen@slm.co m> wrote in message
                  news:%23jMH%23q 2YEHA.1152@TK2M SFTNGP09.phx.gb l...[color=blue]
                  > David,
                  >
                  > I can't seem to get your solution to work. Can you point me to some
                  > documentation on the RowNumber method of the Item object of a row?
                  >
                  > -Sam Matzen
                  >
                  >
                  > "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in[/color]
                  message[color=blue]
                  > news:BDACA264-ECB3-461A-AB8F-4EFB87910AC5@mi crosoft.com...[color=green]
                  > > You can look at the RowNumber property for a cell in the row.
                  > >
                  > > index = row.Item(0).Row Number
                  > >
                  > > HTH
                  > > --
                  > > David Williams, VB.NET MVP
                  > >
                  > >
                  > > "Geoff Jones" wrote:
                  > >[color=darkred]
                  > > > Hi
                  > > >
                  > > > Can anybody help me with the following question?
                  > > >
                  > > > Suppose I have the following code, where myTable is already defined
                  > > > elsewhere:
                  > > >
                  > > > For Each row In myTable.Rows
                  > > > ' Get an index for the row
                  > > > Next
                  > > >
                  > > > Within the loop, I'd like to be able to get hold of the zero based[/color][/color][/color]
                  index[color=blue]
                  > for[color=green][color=darkred]
                  > > > the row being used. I know that I could simply add a variable before[/color][/color][/color]
                  the[color=blue][color=green][color=darkred]
                  > > > loop and then increment it within the loop, but I think there is an[/color][/color]
                  > inbuilt[color=green][color=darkred]
                  > > > function to do it e.g. row.GetIndex(), or whatever.
                  > > >
                  > > > Can anybody help?
                  > > >
                  > > > Geoff
                  > > >
                  > > >
                  > > >
                  > > >[/color][/color]
                  >
                  >[/color]


                  Comment

                  Working...