zoukankan      html  css  js  c++  java
  • VBScript学习笔记

    一、创建对象

    VBScript创建一个对象实例的语法:

    set variablename = CreateObject("Objectname")

    其中,variablename是想要用来保存对象引用的变量,objectname是想要创建的对象的类型。set告诉VBScript要保存的是一个对象的引用,而不是一个常规值。

    二、嵌套对象的引用

    在脚本或Word宏中,经常会看到类似下面的结构

    ActiveDocument.PageSetup.Orientation = wdOrientLandscape
    ActiveDocument.PageSetup.TopMargin = InchesToPoints(0.5)
    ActiveDocument.PageSetup.BottomMargin = InchesToPoints(0.5)
    ActiveDocument.PageSetup.PageWidth = InchesToPoints(11)

    在该示例中,ActiveDocument对象返回一个PageSetup对象。

    通过保存对PageSetup对象的一个引用,可在创建这段脚本时减少很多录入工作,如下所示

    set ps = ActiveDocument.PageSetup
    ps.Orientation = wdOrientLandscape
    ps.TopMargin = InchesToPoints(0.5)
    ps.BottomMargin = InchesToPoints(0.5)
    ps.PageWidth = InchesToPoints(11)

    VBScript有种特别的程序构造,叫With语句。用With语句重写上面的例子:

    with ActiveDocument.PageSetup
        .Orientation = wdOrientLandscape
        .TopMargin = InchesToPoints(0.5)
        .BottomMargin = InchesToPoints(0.5)
        .PageWidth = InchesToPoints(11)
    end with

    三、释放对象

    通过将保存对象的变量值设置为Nothing,可明确释放该对象。

  • 相关阅读:
    POJ
    归并排序+归并排序求逆序对(例题P1908)
    HDU
    2018-12-5 及 codeforces round 525v2
    2018-12-1学习纪录
    近期总结和未来规划
    C++ storage allocation + Dynamic memory allocation + setting limits + initializer list (1)
    注意项
    第四课 计算机的基本组成
    第二课+第三课 计算机系统概论
  • 原文地址:https://www.cnblogs.com/DigiK0ne/p/4018034.html
Copyright © 2011-2022 走看看