vba 如何在vb6中声明用户定义类型的数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3421981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to declare an array of user defined type in vb6
提问by PUG
Type ABFator
a As Single
b As Sinlge
End Type
Dim ABFactorArr(8) As ABFactor
'Basically I want to declare an array of eight ABFactors which I can then access
'基本上我想声明一个包含八个 ABFactor 的数组,然后我可以访问它
I do this and the complier gives error user defined type not defined
我这样做,编译器给出了未定义的错误用户定义类型
Thanks
谢谢
回答by MarkJ
Spelling mistake? Missing c?
拼写错误?缺少 c?
- You've defined the type as
ABFatorwith no c - and you've put the array as
ABFactorwith a c
- 您已将类型定义为
ABFator没有 c - 你已经把数组
ABFactor和 ac 一样
You've also mistyped Singlein your Type definition
您Single在类型定义中也输入错误
Alternatively perhaps you need to make the Type Public, in case you are defining it in one module and using it in another?
或者,您可能需要创建 Type Public,以防您在一个模块中定义它并在另一个模块中使用它?
(Please copy and paste the code into your questions in future, as you've spelt ABFactor three different ways in your question!)
(请在以后将代码复制并粘贴到您的问题中,因为您已经在问题中以三种不同的方式拼写了 ABFactor!)
回答by Andrew Cowenhoven
Put this in the code behind of Form1 at the top of the page:
将其放在页面顶部 Form1 后面的代码中:
Private Type ABFactor
a As Single
b As Single
End Type
Private Sub Form_Load()
Dim ABFactorArr(8) As ABFactor
Dim i As Byte
For i = 0 To UBound(ABFactorArr)
ABFactorArr(i).a = i
ABFactorArr(i).b = i + 10
Next i
'quick test
Debug.Print ABFactorArr(6).b
End Sub

