Results 1 to 3 of 3

Thread: Problem to re-read array

  1. #1

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Resolved Problem to re-read array

    I have a problem to re-read array start from first array. Below is the coding of my program. Can anyone help me to solve this

    cutYear = 1
    currentSize = 0
    j = 0
    i = 0
    maxOpening = 180
    Rotation = 40
    TotalComp = 400

    For i = 0 To TotalComp 'Total compartment

    Age = compHAID(i, 2) + j

    If Age >= 18 And Age <= 40 Then

    If compHAID(i, 3) = 0 Then
    compHAID(i, 3) = cutYear 'label the compartment
    currentSize = currentSize + compHAID(i, 0)

    If currentSize >= maxOpening Then
    currentSize = 0
    i = 0 'Set i = 0 to start read the first array element
    cutYear = cutYear + 1
    j = cutYear - 1

    If cutYear = Rotation Then
    MsgBox "Finished labelling all compartments!", vbOKOnly
    End If

    End If
    Else
    'Do nothing, just ignore the compHAID(i,3) value
    End If
    Else
    compHAID(i, 3) = 0
    End If
    Next i
    Last edited by Bearnerd; Apr 10th, 2006 at 09:49 AM.

  2. #2
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: Problem to re-read array

    Say
    VB Code:
    1. i= -1
    instead of
    VB Code:
    1. i=0
    When
    VB Code:
    1. next i
    is encountered , i is incremented. So if it is set to 0, when it comes
    VB Code:
    1. next i
    it is changed to 1.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Problem to re-read array

    You're resetting the counter variable within the For loop - there's no guarantee what the program will do in that case. Probably just loop infinitely, but it could also blow up.

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