Novice en VBA je rencontre une erreur qui semblerait assez classique mais a laquelle je ne trouve pas de solution. Dans mon code, a chaque assignation de variable lorsque je compile, je me retrouve ac le message d erreur: "SUBSCRIPT OUT OF RANGE".

Mon code est celui-ci:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'-----------------------------------------------------------------------------
' Keyboarding of the initial conditions
'-----------------------------------------------------------------------------
 
deltaz = L / NS
deltat = TT / NT
 
' At time zero
For z = 0 To NS
       C(z, 0) = C0
       temp(z, 0) = temp0
Next z
 
'At other time
 
For t = 1 To TT
 
    '--------------------------------------------------------------------------    
' Initial assumptions for the space cycle
    '--------------------------------------------------------------------------    
    C(0, t) = 0.9999 * C(0, t - 1)      'initial assumption is that C at position 0 is slightly lower from the previous instant
    temp(0, t) = 1.001 * temp(0, t - 1) 'initial assumption is that T at position 0 is slightly higher from the previous instant
 
    '--------------------------------------------------------------------------    
' First boundary conditions
    '--------------------------------------------------------------------------    
    C(1, t) = C(0, t) + deltaz * KM * (Ke * C(0, t) - Cga) / D
    temp(1, t) = temp(0, t) - deltaz * kh * (tempa - temp(0, t)) / h - lambdav * KM * deltaz * (C(0, t) - Cga) / kh
 
 
    '--------------------------------------------------------------------------    
' Keyboarding of the recurring formulas
    '--------------------------------------------------------------------------    For z = 2 To NS
    C(z, t) = deltaz ^ 2 / (D * deltat) * [C(z-1,t)-C(z-1,t-1)] + D / D * [2 * C(z-1, t) - C(z-2, t)]  'D/D because here this quotient is a constant but not in the next case
    temp(z, t) = deltaz ^ 2 / alpha * [(temp(z-1,t)-temp(z-1, t-1))/deltat-M /cp] + 2 * temp(z - 1, t) - temp(z - 2, t)
    Next z
 
    '--------------------------------------------------------------------------    
' Verify second boundary conditions
    '--------------------------------------------------------------------------    
    VC = 0
    VT = 0
 
    If (C(NS, t) - C(NS - 1, t)) / C(NS, t) > ERROR Then
        VC = 1
        C(0, t) = 0.9999 * C(0, t)
        'and we establish a new value for C(o,t)
    End If
 
    If (temp(NS, t) - temp(NS - 1, t)) / temp(NS, t) > ERROR Then
        VT = 1
        temp(0, t) = 1.001 * temp(0, t - 1)
        'and we establish a new value for temp(0, t)
    End If
 
    If VC + VT = 0 Then
    Resume
    'Else: GoTo Line66
    End If
 
Next t
 
End Sub
C est donc a chaque C=... ou temp=... que le debuggeur me dit que l indice n appartient pas a la selection. Je ne comprends pas le probleme. Si l'un de vous pouvait m'aider cela me serait extremement utile.

D'autre part, dans ma derniere boucle If, la commande else GoTo Line66 n a pas l'air de marcher de cette facon. Quelqu'un connait il la synthaxe correcte?

Merci d avance a tous