Excel VBA类型不匹配

问题描述:

在行If infl > (fc - WC(j)) * dz(j) Then我不断收到错误“类型不匹配”,它突出显示行中的-。我现在知道什么会导致这个错误?Excel VBA类型不匹配

Option Explicit 

Dim dz() As Double 
Dim WC() As Double 
Dim fc() As Double 
Dim NL, i As Integer 

Dim sumdrain As Double 
Dim infl As Double 

Sub infilt() 
    Dim j As Integer 
    j = 1 

    While (infl > 0) And (j <= NL) 
    If infl > (fc - WC(j)) * dz(j) Then 
     infl = infl - (fc - WC(j)) * dz(j) 
     WC(j) = fc 
    Else 
     WC(j) = WC(j) + infl/dz(j): infl = 0 
    End If 
    j = j + 1 
    Wend 

    If infl > 0 Then 
    sumdrain = sumdrain + infl 
    infl = 0 
    End If 

End Sub 

fc是一个数组。你不能从中减去。你可能意思是fc(something)

+0

fc是一个数组,但我想从数组中逐个减去个别数字。你对我将如何修改代码有任何建议吗? – user1977802 2013-02-14 22:26:23

+0

yep ...看起来像一个错字...你可能会考虑扩大你的变量名(除了迭代器),以便更容易看到那种错误 – andrew 2013-02-14 22:26:41

+0

如果我用fc替换所有fc(i)我不再得到错误。谢谢 – user1977802 2013-02-14 22:34:52