【问题标题】:Passing a class object into an array of class objects in VB6将类对象传递给VB6中的类对象数组
【发布时间】:2018-05-17 14:10:55
【问题描述】:

所以我有一个问题,起初看起来很简单,但很快就变得令人困惑。

我有一个类对象,我们称它为 customer,它有 2 个变量,firstName 和 secondName。

然后我想将此对象传递到同一对象的数组中,我们称之为 arryCustomers。

所以当我调用 arryCustomers(0) 时,我想传回一个对象,并希望使用 arryCustomers(0).firstName 去除信息。

这将是最理想的情况,但没有人尝试过,而且我正在使用的软件已经有 15 年的历史了,并且已经被少数人接触过,因此编码并不是真正一致的。

我想我想知道的是:这可能是我建议的方式还是有可行的方式?

谢谢

【问题讨论】:

  • 是的,这是可能的。写代码,我相信它会工作的
  • 真的不清楚你想问什么。你问VB6是否支持object arrays
  • 是的,您提议的方式是可行的,而且它正确的方式。只需创建数组并开始使用它。是什么阻止你这样做?

标签: arrays class object vb6


【解决方案1】:

是的,你绝对可以这样做。

Dim arryCustomers() As Customers ' Declare an array of customers
ReDim Preserve arryCustomers(20) ' Dynamically change the size of the array

' Create an instance of a customer and populate the members
Dim Customer0 As New Customers
Set Customer0 = New Customers
With Customer0
    .firstName = "Bob"
    .lastName = "Roberton"
End With

Set arryCustomers(0) = Customer0 ' Set the first element of the array

Debug.Print arryCustomers(0).firstName ' Returns "Bob"

【讨论】:

    猜你喜欢
    • 2011-05-27
    • 2012-08-21
    • 1970-01-01
    • 2016-07-16
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    相关资源
    最近更新 更多