I am trying to read in a single value for WC(1). I would then like to use the initial value of WC(j) in a conditional loop. I get the first value of WC(j) to run smoothly (it meets the first condition in the loop), however, the first condition is supposed to establish the next value in the WC(j) array. However, it doesnt establish a value to the array it just says empty. Specifically in these lines: WC(j) = fc WCinit(j) = WC(j - 1)
When I step through the code, it will say fc=0.3 but WC(j) is empty even though I have set them equal to eachother. Since the WC(j) value is empty, it will only meet the 'else' condition of my loop.
It has the same problem with the next line of code, there is a value for WC(j-1) and it is set equal to WCinit(j), but WCinit(j) stays empty.
Dim Month() As Double
Dim WC() As Variant
Dim WCinit() As Variant
Dim NumMonth As Long, i As Long, j As Long
Dim Precip() As Double
Dim RefET() As Double
Dim Runoff() As Double
Dim Percolation() As Double
Sub main()
WaterBalanceReadMediterranean
WaterBalanceMediterranean
WaterBalanceReadPlains
WaterBalancePlains
End Sub
Sub WaterBalanceReadMediterranean()
NumMonth = 12
ReDim Month(1 To NumMonth)
ReDim WCinit(1 To NumMonth + 1)
ReDim WC(1 To NumMonth + 1)
ReDim Precip(1 To NumMonth)
ReDim RefET(1 To NumMonth)
ReDim Percolation(1 To NumMonth + 1)
ReDim Runoff(1 To NumMonth + 1)
For i = 1 To NumMonth
Month(i) = Cells(4 + i, 1).Value
Precip(i) = Cells(4 + i, 2).Value
RefET(i) = Cells(4 + i, 3).Value
Next i
For j = 1 To 1
WC(j) = Cells(3 + j, 11).Value
Next j
Application.ScreenUpdating = True
End Sub
Sub WaterBalanceMediterranean()
Dim fc As Double
fc = Cells(4, 7).Value
NumMonth = 12
i = 1
j = 2
Dim pwp,dz As Double
Do
If WC(j) >= pwp And (fc - WC(j - 1) + RefET(i)) < Precip(i) Then
Runoff(i) = (Precip(i) - (fc - WC(j - 1) + RefET(i))) * 0.5
Percolation(i) = (Precip(i) - (fc - WC(j - 1) + RefET(i))) * 0.5
WC(j) = fc
WCinit(j) = WC(j - 1)
ElseIf WC(j) >= pwp And (fc - WC(j - 1) + RefET(i)) > Precip(i) Then
Runoff(i) = 0
Percolation(i) = 0
WC(j) = WC(j - 1) + Precip(i) - RefET(i)
WCinit(j) = WC(j - 1)
Else
Runoff(i) = 0
Percolation(i) = 0
WC(j) = pwp
WCinit(j) = WC(j - 1)
End If
j = j + 1
i = i + 1
Loop While j < 14
End Sub
j=0
or whatever value you want beforeDo
– mkingston Feb 28 at 3:07For i = 1 To 1
.j=1: j=2
. – mkingston Feb 28 at 3:08