Results 1 to 1 of 1

Iterating one array by another

Threaded View

  1. #1
    Registered User
    Join Date
    03-28-2013
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Iterating one array by another

    I'm having trouble with my arrays in my code. When I try to pull things from excel forms, everything gets messed up, but when I initialize all the variables in my code, it seems to work. I'm starting to think my problem may be that Range uses two dimensional arrays, while I really only am using a 1D array. Any way to pull the data from excel without it being in a 2D array?

    Here's what I had initially (with variables defined in the code)
    If NumPatientOne > 0 Then
        For k = 1 To 4
        For j = 1 To 3
        For i = 1 To 2
                If CritStagingAvail(i) <= CurrentTime Then
                If HospitalNICUBeds(j) >= 1 Then
                If CCTavail(k) <= CurrentTime Then
                    NumPatientOne = NumPatientOne - 1
                    CritStagingAvail(i) = CurrentTime + CritStagingTime
                    HospitalNICUBeds(j) = HospitalNICUBeds(j) - 1
                    CCTavail(k) = 2 * Distance(j) + CurrentTime + 2 * CCTLoad
                End If
                End If
                End If
        Next i
        Next j
        Next k
    End If
    When I used arrays that pulled from excel, the line that utilized my distance variable stopped working correctly. Here is what I have now:
        For Each j In HospitalNICUBeds
        For Each k In CCTavail
        For Each m In Distance
        For i = 1 To 2
                If NumPatientOne > 0 Then
                If CritStagingAvail(i) <= CurrentTime Then
                If j >= 1 Then
                If k <= CurrentTime Then
                    NumPatientOne = NumPatientOne - 1
                    CritStagingAvail(i) = CurrentTime + CritStagingTime
                    j = j - 1
                    k = 2 * m + CurrentTime + 2 * CCTLoad
                End If
                End If
                End If
                End If
        Next i
        Next
        Next
        Next
    The thing is, I want to iterate Distance by HospitalNICUBeds, but I can't figure out how to do it when using the For Each function. Thanks for your help!
    Last edited by Poolstick; 03-28-2013 at 02:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1