Results 1 to 6 of 6

Thread: For Each Element In Array... Next Element {RESOLVED}

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    4

    For Each Element In Array... Next Element {RESOLVED}

    I am trying to loop through an array "aryDeck" and retrieve an element from the bottom. Place that element into array "aryHand". Drop all elements in "aryDeck" down by one position erasing the first element. This performs the act of actually removing it from the array. Then Redim array "aryDeck" to one less its original value. Then Redim array "aryHand" to one plus its original value.

    Code:

    Dim Card As Variant
    Dim i As Integer
    i = UBound(aryDeck) 'To prevent access of a 53rd element

    For Each Card In aryDeck
    If i <> Card Then
    aryDeck(Card) = aryDeck(Card + 1)
    End If
    Next Card

    I expected "Card" to give me the element number, instead, I get the elements value. How can I get access to the elements number while using the For Each... Next method? Is there a way to access it from the element or do I need to include a counter?


    In addition, the error I get is a "Subscript out of range" error on the Card variable. "aryDeck" is dimensioned as "1 to 52". So "Card" can't be retrieving the elements position in the array. The values entered into "aryDeck" where randomly chosen numbers from "1 to 52." So, it would appear that "Card" is not getting it's value from an elements contents either. This is supported by a boolean "cZero" that would be set to true if a value for "aryDeck" was ever equal '0'. Where then is "Card" getting a '0' value from?
    Last edited by bcamaro85; Jan 9th, 2005 at 10:31 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width