gpt4 book ai didi

arrays - 在VB6中将数组作为参数传递

转载 作者:行者123 更新时间:2023-12-04 03:14:10 25 4
gpt4 key购买 nike

下面的代码杀死了 VB6 (sp6),并在标记的行上的办公室的两台机器上使用“VB.exe 中未处理的异常错误”。

''# Form1.frm
Option Explicit
Private ArrayHolder As Class2

Private Sub Command1_Click()
Set ArrayHolder = New Class2

Dim arr(3) As Long
arr(0) = 1
arr(1) = 2
arr(2) = 3

ArrayHolder.Add arr

End Sub

''# -----------------------------------------------------------
''# Class1.cls
Option Explicit

Private m_myArray() As Long

Public Property Get myArray() As Long()
myArray = m_myArray
End Property

Friend Property Let myArray(ByRef anArray() As Long)
m_myArray = anArray
End Property

''# -----------------------------------------------------------
''# Class2.cls
Option Explicit

Friend Function Add(newArray() As Long) As Class1
Dim oClass As Class1
Set oClass = New Class1

oClass.myArray = newArray <- This kills VB6 dead
MsgBox "passed"

End Function

从我在各种网站上可以看出,我正确地传递了一个数组,但我实际上是否正确地传递了它,为什么它会导致 VB6 如此可怕地消亡?

最佳答案

我没有答案,当然这是一个奇怪的问题,但为什么不添加一个方法并继续前进呢?

'Passed the test
Public Sub LetMyArray(anArray() As Long)
m_myArray = anArray
End Sub


'oClass.MyArray = newArray ' <- This kills VB6 dead
oClass.LetMyArray newArray ' <- This works

关于arrays - 在VB6中将数组作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/852397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com