VBS中inlcude另一个vbs脚本的方法

简介: VBS中inlcude另一个vbs脚本的方法54powerman' Test program for the IncludeFile and ReadConfigFile functions.

VBS中inlcude另一个vbs脚本的方法
54powerman
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName)
   Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
   Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
   IncludeFileAbs FileName
   End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
   Const ForReading = 1
   Dim f: set f = fso.OpenTextFile(FileName,ForReading)
   Dim s: s = f.ReadAll()
   ExecuteGlobal s
   End Sub

IncludeFile "MyClass.vbs"
Dim test
Set test = new MyClass
test.MyFunc

 

VBS中inlcude另一个vbs脚本的方法
54powerman
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName)
   Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
   Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
   IncludeFileAbs FileName
   End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
   Const ForReading = 1
   Dim f: set f = fso.OpenTextFile(FileName,ForReading)
   Dim s: s = f.ReadAll()
   ExecuteGlobal s
   End Sub

IncludeFile "MyClass.vbs"
Dim test
Set test = new MyClass
test.MyFunc

MyClass.vbs代码

Class MyClass
   Public Function MyFunc
   MsgBox "测试VBS调用VBS类"
  End Function
End Class

目录
相关文章
|
SQL 数据库
PowerShell 脚本必备命令
PowerShell 脚本必备命令
|
数据安全/隐私保护
|
XML 数据安全/隐私保护 数据格式
vbs和qtp一些脚本
********************************************************************************************** 用vbs调qtp '编写自动执行指定的QTP脚本的VBS:'利用QTP本身的Quicktest.
1124 0
VBS脚本实例
一、一键升级哨位台核心板程序脚本。 ############################################################ Set ws=WScript.CreateObject("wscript.
877 0
|
Windows 数据安全/隐私保护 安全

热门文章

最新文章