我不能在其他类中使用其他函数中的数组? [英] I can't use an Array thats in un other Function in an other class??

查看:120
本文介绍了我不能在其他类中使用其他函数中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在一个类中的函数中创建了一个数组,现在我需要从另一个类中的其他函数到达那个

数组,我该怎么做?


数组没有固定大小,因为它取决于用户放入

a txt文件的数量。


班级使用Array是一个对象,objInternetClass,我想通过做类似的事来达到


这是MSAgentClass:


一般:

Dim objInternet作为新的InternetClass


私有子InitAgentCommands()


''我会后来在另一个函数中使用这个For循环来获取Name和

的URL,这就像它的样子......


For X = 0到UBound(objInternet.MyArray)步骤2

Debug.Print" objInternet.URLAddress ==> " &安培; objInternet.MyArray(X)

Debug.Print" objInternet.NameAddress ==> " &安培; objInternet.MyArray(X + 1)

Debug.Print" ----------------------------- -------"


Merlin.Commands.Add objInternet.MyArray(X + 1),objInternet.MyArray(X + 1)

,objInternet.MyArray(X + 1)


下一页


结束子


你的,Jonas

I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in
a txt file.

The Class with the Array is an object, objInternetClass and I want to reach
the Array by doing something like
This is the MSAgentClass:

General:
Dim objInternet As New InternetClass

Private Sub InitAgentCommands()

''I will later use this For loop in another function to get both the Name and
the URL, that''s way it looks like this...

For X = 0 To UBound(objInternet.MyArray) Step 2
Debug.Print "objInternet.URLAddress ==> " & objInternet.MyArray(X)
Debug.Print "objInternet.NameAddress ==> " & objInternet.MyArray(X + 1)
Debug.Print "------------------------------------"

Merlin.Commands.Add objInternet.MyArray(X + 1) , objInternet.MyArray(X + 1)
, objInternet.MyArray(X + 1)

Next

End Sub

Yours, Jonas

推荐答案

我无法将阵列公开......


来自帮助文字:

"要创建公共数组,请使用模块的声明

部分中的Public语句来声明数组。


在我的InternetClass中,我从一个文本文件制作数组,我是

在一般声明部门中声明myArray如下:


Public MyArray()As String

但我收到此编译错误消息:


"常量,固定长度字符串,数组,用户定义类型和声明

语句不允许作为对象模块的公共成员


我怎样才能得到公开比??

" BadOmen" < BA ******* @ hotmail.com> skrev i meddelandet

新闻:tL ******************** @ newsc.telia.net ...
I can''t get the Array to be Public...

From the Help text:
" To create a public array, use the Public statement in the Declarations
section of a module to declare the array. "

In my InternetClass where I am making the Array from a text file I am
declaring the myArray in the general Declarations sector like this:

Public MyArray() As String
but I get this Compile Error message:

" Constants, fixed-Length Strings, Arrays, User-defined types and declare
statements not allowed as Public members of object modules "

How can I get it Public than??
"BadOmen" <ba*******@hotmail.com> skrev i meddelandet
news:tL********************@newsc.telia.net...
我已经在一个类中的函数中创建了一个数组,现在我需要从另一个类中的其他函数中获取该数组,我该怎么做?

数组有没有固定的大小,因为它取决于用户将
放入txt文件的程度。

带有数组的类是一个对象,objInternetClass我希望
到达通过做类似
的数组这是MSAgentClass:

一般:
Dim objInternet作为新的InternetClass
私有子InitAgentCommands()

''我稍后会在另一个函数中使用这个For循环来获取Name
和URL,这就是它的样子......

对于X = 0到UBound(objInternet.MyArray)步骤2
Debug.Print" objInternet.URLAddress ==> " &安培; objInternet.MyArray(X)
Debug.Print" objInternet.NameAddress ==> " &安培; objInternet.MyArray(X + 1)
Debug.Print" --------------------------------- ---"

Merlin.Commands.Add objInternet.MyArray(X + 1),objInternet.MyArray(X +
1),objInternet.MyArray(X + 1)

下一页

End Sub

你的,Jonas
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in a txt file.

The Class with the Array is an object, objInternetClass and I want to reach the Array by doing something like
This is the MSAgentClass:

General:
Dim objInternet As New InternetClass

Private Sub InitAgentCommands()

''I will later use this For loop in another function to get both the Name and the URL, that''s way it looks like this...

For X = 0 To UBound(objInternet.MyArray) Step 2
Debug.Print "objInternet.URLAddress ==> " & objInternet.MyArray(X)
Debug.Print "objInternet.NameAddress ==> " & objInternet.MyArray(X + 1)
Debug.Print "------------------------------------"

Merlin.Commands.Add objInternet.MyArray(X + 1) , objInternet.MyArray(X + 1) , objInternet.MyArray(X + 1)

Next

End Sub

Yours, Jonas



" BadOmen" < BA ******* @ hotmail.com>写了
"BadOmen" <ba*******@hotmail.com> wrote
我已经在一个类中的函数中创建了一个数组,现在我需要从另一个类中的其他函数中获取该数组,我该怎么做?

Array没有固定大小,因为它取决于用户放入txt文件的程度。
I have made an array in a function in a Class now I need to get to that
Array from an other function in an other Class, How do I do that?

The Array has no fixed size as it is dependent on how much a user has put in
a txt file.




你应该重新设计你的班级,这样你就不需要暴露数组。

如果你真的需要,你甚至可以让数组成为你能够公开的集合。暴露它。


如果你在互联网课程中有这些内容怎么办:


公共子地址(ByVal索引为长,名称为字符串, URL为字符串)

如果索引> = LBound(MyArray)和索引< = UBound(MyArray)\ 2那么

URL = MyArray(索引* 2)

姓名= MyArray(指数* 2 + 1)

结束如果

结束子


Public Function TotalCommands()As Long

TotalCommands = UBound(MyArray)\ 2

结束功能

然后你可以在其他地方循环使用它们:

Dim x&,nam



You should redesign your class so that you do not need to expose the array.
You might even make the array a collection which you would be able to
expose, if you really need to expose it.

What if you had these in your internet class:

Public Sub Addresses(ByVal Index As Long, Name as String, URL as String)
If Index >= LBound(MyArray) And Index <= UBound(MyArray) \ 2 Then
URL = MyArray(Index * 2)
Name = MyArray(Index * 2 + 1)
End if
End Sub

Public Function TotalCommands() As Long
TotalCommands = UBound(MyArray) \ 2
End Function
You could then loop through them elsewhere:

Dim x&, nam


,url


这篇关于我不能在其他类中使用其他函数中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆