Structure chorm
Dim bit() As Integer
Dim fit As Single
End Structure
Public popcurrent(3) As chorm
Public Sub startpop()
Dim i As Integer, j As Integer, random As Integer, value As Single
For i = 0 To 3
For j = 0 To 5
random = Rnd()
random = random Mod 2
popcurrent(i).bit(j) = random
Next
' modelvalue(popcurrent(i))
' popcurrent(i).fit = fitness()
Next
End Sub
uj5u.com熱心網友回復:
Dim bit(5) As Integer '使用定長Integer陣列
uj5u.com熱心網友回復:
別聽趙四的,type里面可以定義動態陣列。
舉個栗子
Private Type test
inttst As Integer '整形成員
arytst() As Integer '動態陣列成員
End Type
Private Sub Command1_Click()
Dim i As Integer
Dim a As test
ReDim a.arytst(5) '定義陣列成員
a.inttst = 100 '整數成員賦值
For i = 0 To 5 '陣列成員賦值
a.arytst(i) = i * 2
Next
Debug.Print a.arytst(5) '檢驗結果
ReDim a.arytst(10) '再次重定義陣列成員
For i = 0 To 10 '陣列成員賦值
a.arytst(i) = i * 3
Next
Debug.Print a.arytst(10) '檢驗結果
Private Type test
inttst As Integer '整形成員
arytst() As Integer '動態陣列成員
End Type
Private Sub Command1_Click()
Dim i As Integer
Dim a As test
ReDim a.arytst(5) '定義陣列成員
a.inttst = 100 '整數成員賦值
For i = 0 To 5 '陣列成員賦值
a.arytst(i) = i * 2
Next
Debug.Print a.arytst(5) '檢驗結果
ReDim a.arytst(10) '再次重定義陣列成員
For i = 0 To 10 '陣列成員賦值
a.arytst(i) = i * 3
Next
Debug.Print a.arytst(10) '檢驗結果