方法1 —— 借助Class
' 定义一个有多个变量成员的类
Class MultiValue Dim a, b, cEnd ClassFunction ClassMulti(param1, param2, param3)
Dim oClass ' 实例化类 Set oClass = New MultiValue oClass.a = param1 oClass.b = param2 oClass.c = param3 ' 指定函数返回为oClass对象 Set ClassMulti = oClassEnd FunctionDim oClass
Set oClass = ClassMulti("value1","value2","value3") Msgbox oClass.a & vbCrlf & oClass.b & vbCrlf & oClass.c
方法2 —— 借助Dictionary对象
Function DictionaryMulti(param1, param2, param3)
Dim oDict ' 创建字典对象 Set oDict = CreateObject("Scripting.Dictionary") ' 增加键名和键值 oDict("a") = param1 oDict("b") = param2 oDict("c") = param3' 指定函数返回为Dictionary对象
Set DictionaryMulti = oDictEnd FunctionDim oDict, sMsg
Set oDict = DictionaryMulti("value1", "value2", "value3") ' 遍历返回的Dictionary中的键For Each vKey In oDict sMsg = sMsg & oDict.Item(vKey) & vbCrlfNextMsgbox sMsg