Runtime error: 9 - subscribed out of range 2

Asked

Viewed 1,114 times

0

hi! i am having problems with this error. credit that is some problem in the data I entered, but I can not fix.

     Calcul des cumuls annuels sur l'année hydrologique (1er septembre au 31 aout)

  For k = 1 To nbannees - 1
     For j = 1 To 12
         PluieAnnHy(k) = PluieAnnHy(k) + PluieMens(12 * (k - 1) + 8 + j)
         ETPAnnHy(k) = ETPAnnHy(k) + ETPMens(12 * (k - 1) + 8 + j)
         TemperAnnHy(k) = TemperAnnHy(k) + TemperMens(12 * (k - 1) + 8 + j)
         DebitAnnHy(k) = DebitAnnHy(k) + DebitMens(12 * (k - 1) + 8 + j)
          If dataneige_exist = True Then NeigeAnnHy(k) = NeigeAnnHy(k) + 
  NeigeMens((12 * (k - 1) + 8 + j))
  Next
  TemperAnnHy(k) = TemperAnnHy(k) / 12
  DebitAnnHy(k) = DebitAnnHy(k) / 12

1 answer

1

What I see first is that the internal is did not have its next try the code below.

         ' Calcul des cumuls annuels sur l'année hydrologique (1er septembre au 31 aout)

  For k = 1 To nbannees - 1
     For j = 1 To 12
         PluieAnnHy(k) = PluieAnnHy(k) + PluieMens(12 * (k - 1) + 8 + j)
         ETPAnnHy(k) = ETPAnnHy(k) + ETPMens(12 * (k - 1) + 8 + j)
         TemperAnnHy(k) = TemperAnnHy(k) + TemperMens(12 * (k - 1) + 8 + j)
         DebitAnnHy(k) = DebitAnnHy(k) + DebitMens(12 * (k - 1) + 8 + j)
          If dataneige_exist = True Then
            NeigeAnnHy(k) = NeigeAnnHy(k) + NeigeMens((12 * (k - 1) + 8 + j))
          End If
    Next j
  Next k

  TemperAnnHy(k) = TemperAnnHy(k) / 12
  DebitAnnHy(k) = DebitAnnHy(k) / 12
  • The use of Option Explicit helps prevent this kind of error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.