文章目录

http://blog.csdn.net/rainylin/article/details/2173029
http://www.cnblogs.com/BeyondTechnology/archive/2011/01/10/1932440.html

Basic

  • windows 脚本解释程序: wscript.exe(Windows Scripting Host)
    wscript.exe 可以执行 .vbs, .wsh, .js 等程序

  • 不区分字符的大小写

  • 变量在声明的时候不能初始化

  • 一行可以写多条语句,语句以冒号分开

  • 一条语句可以分多行书写, 空格加下划线来续航

  • 无转义字符, 两个引号表示引号本身,或者是使用Chr(34)

  • Variant
    variant类型(任何类型),效率低

  • Boolean
    2B True,False

  • Byte
    1B 0-255

  • Integer
    2B -32768 - 32767

  • Long
    4B -2147483648 - 2147483647

  • String
    1-65400B

  • Currency
    8B -922337203685477.5808 - 922337203685477.5807

  • Date
    8B 100年1月1日 - 9999年12月31日

  • Object
    4B 包含对某个对象的引用(地址)

  • Single
    4B -3.402823E38 - 1.401298E-45

= 相等或赋值
is 对象比较
& 字符串连接
* 乘法
/ 除法
\ 整数除法
mod 取余
^ 乘方
= < > <= >= <> like is and not or xor eqv imp

dim k  'Variant类型(任何类型),效率很低dim i as Byte,j as long 'Byte:1B; Long:4B
const BOOKPRICE as single = 23.50 'Single:4B,单精度浮点类型
dim strStudents(9) as string  '数组,0-9是个元素
dim iTable(4,4) as integer '二维数组,Integer:2B
dim DyArray() as boolean '动态数组

enum SecurityLevel  '枚举类型
  illegalEntry = -1
  level1 = 0
  level2 = 1
end enum

type Person  '自定义数据类型
  MyName as string
  MyBirth as date '14B, 100.1.1~9999.12.31
end type

if condition then
  a = b + 1;
else if condition then
  a = b - 1;
else
  a = 2;
end if
select case Pid
case "A101"
  Price = 1;
case Is > 8
  Price = 2;
case else
  Price = 0;
end select
for each elem in group
  exit for '跳出循环
next elem

do while condition
loop

rem Static sub...表实现体内的局部变量的值被保留到下次调用
sub subname (arg1,arg2)
  exit sub '跳出过程
end sub

rem Private Function...表本模块可见
private function funname (arg1,arg2) '可看做具有返回值的过程Sub
  funname = expression '将要返回的值赋给函数名
  exit function '跳出函数

end function

Functions

IsNumeric IsDate IsEmpty IsArray IsObject IsNull(expression)
Sin Cos Tan Log Abs Int Fix

Trim(String)
LTrim(String)
Rtrim(String)
InStr([start,]strForSearch,strSearchFor[,compare]) '默认从第一个字符开始搜索(时用二进制匹配compare=0),返回搜索到的字符在第几个字符
InStrRev '从后面找起
Left(String,x) '取string左端x个字符组成的字符串, Right(String,x)
Mid(String,start,x) '取string从start位开始的x个字符组成的字符串
Ucase(String) Lcase(String) Space(x) '返回x个空白的字符串
CStr(expression) '转换为String型, CInt CDbl CBool

' date
Now() '返回计算机系统设置的日期和时间的Variant(Date)
Date() '返回包含系统日期的Variant(Date)
Time() '返回一个指明当前系统时间的Variant(Date)
Second(time) 'Variant(Integer),0-59
Minute(time) 'Variant(Integer),0-59
Hour(time) 'Variant(Integer),0-24
Day(date) 'Variant(Integer),0-31
Month(date) 'Variant(Integer),1-12
Year(date) 'Variant(Integer)
Weekday(date,[firstdayofweek]) 'Variant(Integer),1-7

' file
Kill pathname  '删除文件
RmDir pathname '删除目录
Open pathname For mode 'mode:Append,Binary,Input,Output,Random(default)
Close [filenumber]
Input #filenumber
Get #filenumber varname
Put #filenunber,varname
Write #filenumber,[outputlist]

Demo

' Shortcut
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") '取得桌面的路径
set oLink = WshShell.CreateShortcut(strDesktop & "\QQ.lnk")
oLink.TargetPath = "d:\usr\Tencent\Bin\qq.exe"
oLink.Arguments = ","
oLink.WindowStyle = 1  '快捷方式里的“运行方式”
oLink.Hotkey = ""
oLink.IconLocation = "d:\usr\Tencent\Bin\qq.exe, 0"
oLink.Description = "腾讯QQ"
oLink.WorkingDirectory = "d:\usr\Tencent\Bin"
oLink.Save  '建立快捷方式

' pin to taskbar
' https://www.codeproject.com/Tips/713824/Pin-a-shortcut-onto-the-Taskbar-or-Start-Menu
Pin.vbs "%systemroot%\explorer.exe" "Windows Explorer" false ","