3
遇到此錯誤的問題。我正在創建一個GA,循環將我的健身值分配給一個數組。VBA宏運行時錯誤6:循環內的溢出編碼
一些變量
Dim Chromolength as integer
Chromolength = varchromolength * aVariables
Dim i as integer, j as integer, counter as integer
Dim Poparr() As Integer
Dim FitValarr() As Integer
代碼:我有問題
ReDim Poparr(1 To PopSize, 1 To Chromolength)
For i = 1 To PopSize
For j = 1 To Chromolength
If Rnd < 0.5 Then
Poparr(i, j) = 0
Else
Poparr(i, j) = 1
End If
Next j
Next i
For i = 1 To PopSize
j = 1
counter = Chromolength
Do While counter > 0
FitValarr(i) = FitValarr(i) + Poparr(i, counter) * 2^(j - 1)
j = j + 1
counter = counter - 1
Loop
Next i
:
FitValarr(i) = FitValarr(i) + Poparr(i, counter) * 2^(j - 1)
我道歉,我是相當新的VBA。
您是否將FitValarr標註爲'FitValarr(1到PopSize)'? –
uhm no ...我應該添加 ReDim FitValarr(1到PopSize) –