【发布时间】:2015-10-05 23:55:09
【问题描述】:
似乎没有其他答案对我有用,所以我求助于一个每个人都认为有问题的问题。除了 VBA 之外的任何其他语言的简单内容。我只想初始化一个全局字符串数组,并在我的主子中使用它。
这是我刚刚尝试从公共函数返回的 test1:
Public Function effthis1() As String()
ReDim effthis1(0 To 10)
myStr = "a b c d e f g h i j k"
strsplit = Split(myStr)
j = LBound(effthis)
For Each word In strsplit
effthis1(j) = word
j = j + 1
Next
End Function
Sub test1()
testStr = effthis1(4)
MsgBox testStr
End Sub
这是 test2,我尝试使用在主子中调用的子:
Public effthis2() As String
Sub declareMyArray()
effthis2(0) = "a"
effthis2(1) = "b"
effthis2(2) = "c"
effthis2(3) = "d"
effthis2(4) = "e"
effthis2(5) = "f"
effthis2(6) = "g"
effthis2(7) = "h"
effthis2(8) = "i"
effthis2(9) = "j"
effthis2(10) = "k"
End Sub
Sub test2()
declareMyArray
MsgBox effthis2(4)
End Sub
MSDN 根本没有帮助。在此先感谢,乔治
【问题讨论】:
-
如果你想在任何子或函数中使用变量,你必须在顶部声明它,在第一个子或函数之前