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,可明确释放该对象。

  • 相关阅读:
    node.js ---path模块
    es6箭头函数this问题
    Codeforces Round #576 (Div. 2) | CF1199 补题
    Hungary
    CF 1196D2 RGB Substring (hard version) --- 前缀和 + 思维
    康托展开
    POJ1821 Fence --- 单调队列 + DP
    素数筛
    自动化接口面试遇到的问题
    linux遇到的面试问题
  • 原文地址:https://www.cnblogs.com/DigiK0ne/p/4018034.html
Copyright © 2011-2022 走看看