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

  • 相关阅读:
    jquery的一些用法
    js函数:setInterval()/clearInterval()——js网页计时器
    oracle递归查询
    子查询
    oracle分析函数
    前端的UI设计与交互之设计原则篇
    用js编解码base64
    总结的Javascript插件
    vuex2中使用mapMutations/mapActions报错解决方法 BabelLoaderError: SyntaxError: Unexpected token
    form表单里的故事
  • 原文地址:https://www.cnblogs.com/DigiK0ne/p/4018034.html
Copyright © 2011-2022 走看看