有没有办法在声明公共变量的同时赋值?
这是sub中的代码,它可以完美地工作:
Option Explicit
Sub test()
Dim arrStatistics As Variant
'Set arrStatistics
arrStatistics = Array("H/T - Goal Scored", "H/T - Goal Conceded", "H/T - Both teams Scored", "H/T - Over 0.5", "H/T - Over 1.5", "H/T - Over 2.5", "H/T - Result" _
, "F/T - Goal Scored", "F/T - Goal Conceded", "F/T - Both teams Scored", "F/T - Over 0.5", "F/T - Over 1.5", "F/T - Over 2.5", "F/T - Result")
End Sub这就是声明变量作为Public的方法
Public arrStatistics As Variant但是当我使用这个的时候,我收到了一个错误:
Public arrStatistics As Variant
'Set arrStatistics
arrStatistics = Array("H/T - Goal Scored", "H/T - Goal Conceded", "H/T - Both teams Scored", "H/T - Over 0.5", "H/T - Over 1.5", "H/T - Over 2.5", "H/T - Result" _
, "F/T - Goal Scored", "F/T - Goal Conceded", "F/T - Both teams Scored", "F/T - Over 0.5", "F/T - Over 1.5", "F/T - Over 2.5", "F/T - Result")发布于 2019-09-05 21:00:41
否,您必须在过程外部声明变量为public
Option Explicit
Public arrStatistics As Variant然后用一个过程初始化内容。
Public Sub InitPublicVariabels()
arrStatistics = Array("H/T - Goal Scored", "H/T - Goal Conceded", "H/T - Both teams Scored", "H/T - Over 0.5", "H/T - Over 1.5", "H/T - Over 2.5", "H/T - Result" _
, "F/T - Goal Scored", "F/T - Goal Conceded", "F/T - Both teams Scored", "F/T - Over 0.5", "F/T - Over 1.5", "F/T - Over 2.5", "F/T - Result")
End Sub但是,与在代码中包含大量数据不同,您可以选择将数据放入一个隐藏的工作表中,这样您就可以轻松地将其读入数组。更方便地编辑数据,并且是分离代码和数据的良好实践。
https://stackoverflow.com/questions/57806027
复制相似问题