I'm getting a "subscript out of range" error on the following code and I can't for the life of me figure out why.
The line marked in red is where I'm getting the error. The error occurs on the first pass through the For..Next loop when intCount = 2. I don't understand how a subscript of 2 can be out of range when the array has an upper boundary of 4.
Thanks in advance,
Jas
Code:
' General declarations
Option Base 1
Public varPay as Variant
Public Sub Userform_Initialize()
varPay = Array(4)
End Sub
Public Sub cmdAdd_Click()
Dim intCount, intTemp as Integer
intTemp = 10
varPay(1) = 10
For intCount = 2 To 4
If intTemp < 22 then
intTemp = intTemp + 7
Else
intTemp = intTemp - 21
End If
Code:
varPay(intCount) = intTemp
Code:
Next intCount
.
.
.
.
End Sub
The line marked in red is where I'm getting the error. The error occurs on the first pass through the For..Next loop when intCount = 2. I don't understand how a subscript of 2 can be out of range when the array has an upper boundary of 4.
Thanks in advance,
Jas