📜  面向对象的VBScript

📅  最后修改于: 2020-10-19 04:10:31             🧑  作者: Mango


什么是对象

VBScript运行时对象可以帮助我们完成各种任务。本节将帮助您了解如何实例化对象并使用它。

句法

为了无缝处理对象,我们需要声明对象并使用Set Keyword实例化它。

Dim objectname    'Declare the object name
Set objectname = CreateObject(object_type)

在下面的示例中,我们正在创建Scripting.Dictionary类型的对象。

Dim obj  
Set obj = CreateObject("Scripting.Dictionary")

销毁对象

销毁对象的意义在于释放内存并重置对象变量。

句法

为了销毁对象,我们需要使用Set Keyword和对象名称,然后将其指向Nothing

Set objectname = Nothing 'Destroy the object.

在下面的示例中,我们正在创建Scripting.Dictionary类型的对象。

Dim obj  
Set obj = CreateObject("Scripting.Dictionary")
Set obj = Nothing.

对象用法

请单击每种给定的对象类型以了解更多信息。

Object Type Description
Class Class is a container, which holds methods and variables associated with it and accessed by creating an object of Type Class.
Scripting.FileSystemObject It is the group of objects with which we can work with file system.
Scripting.Dictionary A Group of objects, which are used for creating the dictionary objects.
Debug A Global Object with which we can send output to the Microsoft script debugger.