DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Enumerate a collection

  1. #1
    Rob Guest

    Enumerate a collection

    Hi, I am having a problem enumerating a collection within a class.
    The first loop works fine. On the second loop intTCnt does not seem to be
    recreated but seems to be holding the count from the previous loop. That is
    to say:
    loop 1
    intTCnt = 1
    loop 2
    intTCnt = 2
    intTCnt = 3
    I think it shoud be:
    loop1
    intTCnt = 1
    loop2
    intTCnt =1
    intTCnt = 2

    There are only 3 records to deal with in the db.
    Here is the code.
    Thank In Advance.
    Rob

    For intATemp = 1 To MycolAccounts.Count
    intACnt = intACnt + 1
    Dim intTCnt As Integer'<<<<Problem Here on loop 2
    Dim intTTemp As Integer
    For intTTemp = 1 To MycolAccounts(intACnt).Transactions.Count
    intTCnt = intTCnt + 1
    strTransList = strTransList & Chr(13) &
    MycolAccounts(intACnt).Transactions.Item(intTCnt).TransID
    Next intTTemp
    Next intATemp'<<<<Shouldnt intTCnt get destroyed here?



  2. #2
    Eduardo A. Morcillo [MVP-VB] Guest

    Re: Enumerate a collection

    > Next intATemp'<<<<Shouldnt intTCnt get destroyed here?

    No. The variable scope is the function not the For..Next. You have to
    explicitly set the variable to 0.

    --
    Eduardo A. Morcillo [MS MVP - VB]
    http://www.domaindlx.com/e_morcillo



  3. #3
    Rob Guest

    Re: Enumerate a collection


    "Eduardo A. Morcillo [MVP-VB]" <emorcilloATmvps.org> wrote in message
    news:3e69f60f@tnews.web.devx.com...
    > > Next intATemp'<<<<Shouldnt intTCnt get destroyed here?

    >
    > No. The variable scope is the function not the For..Next. You have to
    > explicitly set the variable to 0.

    Thanks Works great.

    >
    > --
    > Eduardo A. Morcillo [MS MVP - VB]
    > http://www.domaindlx.com/e_morcillo
    >
    >




  4. #4
    Arthur Wood Guest

    Re: Enumerate a collection


    "Eduardo A. Morcillo [MVP-VB]" <emorcilloATmvps.org> wrote:
    >> Next intATemp'<<<<Shouldnt intTCnt get destroyed here?

    >
    >No. The variable scope is the function not the For..Next. You have to
    >explicitly set the variable to 0.
    >


    Just to throw a bit of confusion into the mix, while VB 6 and earlier versions
    only hold the Lowest level of SCOPE at the Procedure/Function level, in .NET,
    the lowest level of Scope is the BLOCK level (as you thought was the case
    here). With BLOCK-level scope, then your question about intATemp 'being
    destroyed' (read going out of scope) WOULD BE correct. VB 6 DOES NOT support
    any type of BLOCK-LEVEL scope.

    AW



    >--
    >Eduardo A. Morcillo [MS MVP - VB]
    >http://www.domaindlx.com/e_morcillo
    >
    >



  5. #5
    Rob Guest

    Re: Enumerate a collection


    "Arthur Wood" <wooda@nospam.com> wrote in message
    news:3e6a68a2$1@tnews.web.devx.com...
    >
    > "Eduardo A. Morcillo [MVP-VB]" <emorcilloATmvps.org> wrote:
    > >> Next intATemp'<<<<Shouldnt intTCnt get destroyed here?

    > >
    > >No. The variable scope is the function not the For..Next. You have to
    > >explicitly set the variable to 0.
    > >

    >
    > Just to throw a bit of confusion into the mix, while VB 6 and earlier

    versions
    > only hold the Lowest level of SCOPE at the Procedure/Function level, in

    ..NET,
    > the lowest level of Scope is the BLOCK level (as you thought was the case
    > here). With BLOCK-level scope, then your question about intATemp 'being
    > destroyed' (read going out of scope) WOULD BE correct. VB 6 DOES NOT

    support
    > any type of BLOCK-LEVEL scope.
    >
    > AW

    Thanks again. The main reason I didnt catch that, I did try setting it to 0,
    but I had built too many for..next loops at one time and, incorrectly
    assumed the first was working right. Im learning though, one thing at a
    time...
    >
    >
    >
    > >--
    > >Eduardo A. Morcillo [MS MVP - VB]
    > >http://www.domaindlx.com/e_morcillo
    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center