返回列表 发帖

[问题求助] 【已解决】请问在vbs中,函数如何返回在其中创建的对象?

我写的代码如下:
━┉┉┉┉┉┉┉∞┉┉┉┉┉┉┉┉∞┉┉┉┉┉┉┉━
Option Explicit
Call main()
Function main()
Dim tmpObj
tmpObj = RetObj()
End Function
Function RetObj()
Dim WshShell
Set WshShell = WScript.CreateObject("Wscript.Shell")
RetObj = WshShell
End FunctionCOPY
运行报告错误
━┉┉┉┉┉┉┉∞┉┉┉┉┉┉┉┉∞┉┉┉┉┉┉┉━

我的问题:
━┉┉┉┉┉┉┉∞┉┉┉┉┉┉┉┉∞┉┉┉┉┉┉┉━
RT,怎么才能正确的返回对象呢,请不要使用全局变量。谢谢大家的帮助
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

回复 5# yiwuyun


    非常真诚的感谢您!

TOP

Option Explicit
Call main()
Function main()
        Dim tmpObj
   Set     tmpObj = RetObj()
End Function
Function RetObj()
        Dim WshShell
        Set WshShell = WScript.CreateObject("Wscript.Shell")
     Set   RetObj = WshShell
End FunctionCOPY
1

评分人数

TOP

回复 2# CrLf


    好像不可以哦。

TOP

谢谢楼上回复,还是不行。

TOP

Set RetObj = WshShellCOPY

TOP

返回列表