小编Sn_*_*Srm的帖子

无法将字典作为参数传递给VBA函数

我有一个VBA函数,它应该将Dictionary作为参数:

Function ShowDict(Dict1 As Dictionary)
   For Each x In Dict1
        MsgBox (Dict1.Item(x))
   Next
End Function
Run Code Online (Sandbox Code Playgroud)

我试图通过以下方式调用它:

Dim Dict As Dictionary
Set Dict = Dictionary
Dict.Add "Owner", "John"
Dict.Add "Employee", "Sam"
ShowDict (Dict)
Run Code Online (Sandbox Code Playgroud)

在定义词典之前,我确实从References中选择了Microsoft Scripting References.但是,当我尝试使用'Dict'作为参数调用函数时,我得到一个编译错误,声明' Argument not optional '.谁能帮我?

ms-access vba dictionary ms-access-2007 access-vba

4
推荐指数
1
解决办法
1313
查看次数

如何从具有元素和频率的哈希创建数组

我有一个散列,其中每个键对应于它的频率:

hsh = {'a' => 2, 'b' => 3, 'c' => 1}
Run Code Online (Sandbox Code Playgroud)

我想分解成一个数组:

arr = ['a', 'a', 'b', 'b', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)

我使用以下方法工作正常,但是有更好的方法吗?

arr = []
hsh.each do |x,y|
  y.times do
    arr << x
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby

1
推荐指数
1
解决办法
68
查看次数

标签 统计

access-vba ×1

dictionary ×1

ms-access ×1

ms-access-2007 ×1

ruby ×1

vba ×1