vba:从函数返回字典 [英] vba: return dictionary from function

查看:886
本文介绍了vba:从函数返回字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这对我来说不起作用,目前还不清楚为什么。



提前感谢您的任何和所有帮助。

  Sub mySub()
dim myDict as字典
myDict =新词典

myDict = myFunc()

End Sub

函数myFunc()
dim myDict2
set myDict2 = new Dictionary

'一些代码可以做的事情,并添加到myDict2'

myFunc = myDict2
结束函数


解决方案

您需要使用SET关键字,只要您分配一个对象而不是

  Sub mySub()
dim myDict as Dictionary
set myDict = myFunc()
End Sub

函数myFunc()作为字典
dim myDict2作为字典
设置myDict2 =新字典
'一些代码,做的事情和添加到myDict2'
设置myFunc = myDict2
结束函数

您的原始代码还将创建myDict作为新的Dictionary对象,然后立即将其替换为不同的。您可以跳过该步骤。


this outlines what i am trying to do.

this is not working for me, and it is unclear why.

thank you in advance for any and all help.

        Sub mySub()
        dim myDict as Dictionary
            myDict=new Dictionary

                myDict=myFunc()

        End Sub

        Function myFunc()
            dim myDict2
                set myDict2 = new Dictionary

                    'some code that does things and adds to myDict2'

            myFunc=myDict2
        End Function

解决方案

You'll need to use the SET keyword anytime you are assigning an object instead of a value:

    Sub mySub()
        dim myDict as Dictionary
        set myDict = myFunc()
    End Sub

    Function myFunc() as Dictionary
        dim myDict2 as Dictionary
        set myDict2 = new Dictionary
                'some code that does things and adds to myDict2'
        set myFunc=myDict2
    End Function

Your original code was also creating myDict as a new Dictionary object, then immediately replacing it with a different one. You can just skip that step.

这篇关于vba:从函数返回字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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