使用单个变量一切正常,动态数组出现问题。
有一个带有全局变量的模块:
Option Compare Database
Option Explicit
Global gbl_numberOfPositions As Integer
Global gbl_numberOfDisciplines As Integer
Global gbl_mv_clsJobPostions() As clsJobPostion
Public Sub Init_Globals()
gbl_numberOfPositions = 0
gbl_numberOfDisciplines = 0
ReDim gbl_mv_clsJobPostions(0)
End Sub
在第一种形式中定义了动态数组
Private Sub Form_Load()
Call Init_Globals
End Sub
Private Sub InitCBox()
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset(strSQL)
rs.MoveLast
ReDim gbl_mv_clsJobPositions(rs.RecordCount)
rs.MoveFirst
i = 1
Do While (Not rs.EOF)
Set gbl_mv_clsJobPositions(i) = New clsJobPostion
gbl_mv_clsJobPositions(i).InitializeMe _
rs![ID Job Position], rs![ID Position], rs![ID Discipline]
i = i + 1
rs.MoveNext
Loop
Debug.Print UBound(gbl_mv_clsJobPositions)
End Sub
然后加载第二个:
Private Sub Form_Load()
Debug.Print UBound(gbl_mv_clsJobPostions)
End Sub
但是返回两个不同的。在第二种情况下,它为零。
所以我的问题是如何在表单之间传递动态数组?