您好我有一系列子程序如下:
DataCollection() :从电子表格中收集数据并将其写入自定义类型变量。
NewSub() :做其他事情,但与问题无关。
我想保留先前声明的相同变量,并在第二个子中分配值。我想我必须以某种方式使它们成为全局变量,但到目前为止无法解决,无论我做什么,我都会得到变量未定义错误。我的代码如下:
Option Explicit
Public Type Trucks
NumberOfAxles As Integer
AxleWeights(15) As Double
End Type
Public Sub DataCollection()
Dim NumberOfTrucks As Integer
Truck(10) As Trucks
Dim i, j, k As Integer
'Determine Number of Trucks
NumberOfTrucks = Cells(6, 8)
'Populate Truck Arrays (Trucks 1 to 5)
k = 0
For i = 1 To 5
Truck(i).NumberOfAxles = Cells(9, 4 + 4 * k)
k = k + 1
Next i
k = 0
For i = 1 To 5
For j = 1 To Truck(i).NumberOfAxles
Truck(i).AxleWeights(j) = Cells(31 + j, 3 + 4 * k)
Next j
k = k + 1
Next i
End Sub
Public Sub NewSub()
For i = 1 To Truck(10).NumberOfAxles
Cells(27 + i, 22) = Truck(10).AxleWeights(i)
Next i
End Sub
任何想法都将受到欢迎!谢谢!