• VBScript学习笔记


    (一)运算符

    1. +运算符可连接字符串

            fullname = firstname + " " + lastname

        但推荐使用&运算符,&专用于字符串连接

            fullname = firstname & " " & lastname

    2. 算术运算符:

            ^        求幂

            /         除法

                     整除

            mod   模除

    3. 比较运算符:

            =        等于      ‘VB中,逻辑运算的“等于”运算符和赋值使用相同的运算符

            <>     不等于

            is        对象相等

    4. 逻辑运算符:

            not     取反

            and    逻辑与

            or       逻辑或

            xor     异或(不同的)

            eqv    相等性(相同的) false eqv false = True

            imp    蕴含(相同值或第二个值为True)

    (二)自动类型转换

    数字(Number) +/- 字符串(String) 如果字符串表示一个数字,把它转换为数字,且结果也为数字,否则报错
    日期/时间(Date/time) +/- 数字(Number)

    数字的整数部分作为天数与日期相加。小数部分作为时间偏移量与天数相加,当做一天的小数部分(1s = 0.0000115741;12h = 0.5)

    日期 +/- 字符串 若字符串表示数字,则将其转换为数字,结果为日期,否则报错
    任意类型 & 任意类型 把任意类型的值转换为字符串,并把字符串相连接

    (三)流程控制

    1. if...Then语句

    if condition then

        ...

    elseif othercondition then

        ...

    else

        ...

    end if

    2. Select Case语句

    select case variable

        case value: statements

        case value:

            statements

        ...

    end select

    ’value可以是变量。当variable满足多个value时,只执行第一个匹配的case语句。

    3. do while循环

    1) do while condition

            statements

        loop

    2) do until condition

            statements

        loop

    3) do

            statements

        loop while condition

    4) do

            statements

        loop until condition

    5) '从循环内部结束循环

    '使用exit do语句

    do

        statements

        if condition then exit do

        statements

    loop

    while形式(1), 3) ):condition为true时循环;

    until形式(2), 4) ):condition为fasle时循环;

    do在前(3), 4) ):不论condition如何,至少先执行一次语句。

    4. for...next语句计数

    1) for counter = startvalue to endvalue

            statements

            ...

        next

    2) for counter = startvalue to endvalue step stepvalue

            statements

            ...

        next

    'stepvalue可以是负值

    5. 使用for each处理集合和数组

    集合(collection)变量类型:文件名、用户名或者包含在单个变量中的其他数据的一个列表

    集合与数组的区别(转自http://blog.sina.com.cn/s/blog_5b7bfe100100mt2t.html):

    集合可以根据需要扩充,不像数组那样需要预先规定大小。往集合中插入元素或删除元素,集合都能自动处理。

    除Variant类型的数组外,数组只能保存在声明时所规定的数据类型;但同一个集合中可以存储不同类型的数据。

    尽管不知道元素的位置,但通过主题词可以很快地访问到集合中的元素,也可以按数组的方法由元素的序号读取元素值,很灵活。

    集合元素的修改不如数组元素方便,必须先删除然后再添加。

    处理集合的速度要比数组慢得多。

    1) set fso = CreateObject("Scripting.FileSystemObject")

        set tempfiles = fso.GetFolder("C:TEMP").Files

        filelist = " "

        for each file in tempfiles

            filelist = filelist & ", " & file.name

        next

        MsgBox "The temp files are:" & filelist

    2) dim names[10]

        ...

        for each nm in names

            ...

        next


    使用书籍:《Windows 7 脚本编程和命令行工具指南》(Windows 7 and Vista Guide to Scripting, Automation, and Command Tools) Brian Knittle著

  • 相关阅读:
    win7 windows server 2008R2下 https SSL证书安装的搭配(搭配https ssl本地测试环境)
    (转载)数据库表设计-水电费缴费系统(oracle)
    考勤系统——代码分析datagrid
    (转载)模拟银行自助终端系统
    Amazon验证码机器算法识别
    [译] 理解 LSTM 网络
    循环神经网络(RNN, Recurrent Neural Networks)介绍
    机器学习之线性分类器(Linear Classifiers)——肿瘤预测实例
    word2010无法显示endnote x7插件及破解endnote x7
    ubuntu16.04+caffe训练mnist数据集
  • 原文地址:https://www.cnblogs.com/DigiK0ne/p/4014640.html
Copyright © 2020-2023  润新知