【发布时间】:2020-08-10 13:45:56
【问题描述】:
我正在尝试编写 3 个用户定义的类型变量,它们需要像这样相互关联;
Type tdrivers
Strfirstname as string
Strsurname as string
Intage as integer
End type
Type Tcars
Strmake as string
Strmodel as string
Lngcc as long
Driverid() as tdrivers
End type
Type T_Race
Strlocation as string
DteRacedate as date
IntYear as integer
CarsID() as Tcars
End Type
Sub CreateRace()
Dim myrace() as T_Race
'Variables to hold integer 'values at runtime
Dim A as integer
Dim B as integer
Dim C as integer
'this line redims myrace ok
Redim myrace(A)
'This line doesn't do anything
'When I try to redim the 'carsID() array nested inside 'the myrace(A) like so;
Redim myrace(A).carsID(B)
'This line obviously does 'nothing either
Redim myrace(A).CarsID(B).driverid(C)
我需要能够将比赛分配给 myrace() 数组,然后将赛车分配给他们参加的每场比赛,然后将车手分配给他们驾驶的赛车。所以carsID() 必须嵌套在myrace() 中,而driverid() 必须嵌套在carsID() 中
一旦我知道如何在其中重新调整carsID(),就可以重新调整嵌套在其中的Driverid()。
如果我将所有数组固定为一个常数值,例如 8,那么子程序运行正常,所有比赛、汽车和车手都正确嵌套。它对嵌套动态数组的 redim 失败了。希望这是有道理的。任何人都可以帮忙。谢谢
【问题讨论】:
-
在您尝试 ReDim 之前,A、B 是否有值?在 ReDim x(0) 之后你会期待什么?
-
是的,A、B 和 C 变量都在 redim 完成之前分配了值。只有 myrace(A) 会自行重新调整尺寸,但会在以下情况下失败;
-
继续。 CarsID(B) 像这样嵌套时不会重新调整尺寸; redim myrace(A).carsID(B)