网站如何建设成直播间,高端网站建设专业公司,邯郸做网站推广找谁,经验推广一、VBS介绍 VB6.0分为VBS#xff08;脚本#xff09;和VBA#xff08;宏#xff09; 代码强度#xff1a;VB6.0 VBS VBA 编程工具#xff1a;PrimalScript. Enterprise
二、基本操作 Dim 定义变量 VB只有一种数据类型#xff0c;但有多个子类型#xff0c;… 一、VBS介绍 VB6.0分为VBS脚本和VBA宏 代码强度VB6.0 VBS VBA 编程工具PrimalScript. Enterprise
二、基本操作 Dim 定义变量 VB只有一种数据类型但有多个子类型变量在赋值时才会确定子类型 If语句 If...Then...Else...End If If...Then...ElseIf...Then...Else...End If Select Case语句 Select Case Case Case Else End Select 循环语句 Do While 条件...Loop 条件为True时循环语句执行次数0 Do...Loop While 条件 条件为True时循环语句执行次数1 Do Until 条件...Loop 条件为False时循环语句执行次数0 Do...Loop Until 条件 条件为False时循环语句执行次数1 While...Wend For i0 To 10 (Step 2/-2)...Next Step意为i每次递增2或递减2 For Each...in...Next 用于处理集合 数组下标从0开始字符串从1开始 字符串连接符 三、常用函数 InputBox 输入 MsgBox 输出 Wscript.Echo 输出到Output面板 IsNumeric 判断是否整型 CStr 变量转成字符串型 CDble 变量转成双精度型 Split(str, ,) 把字符串按照分隔符进行分割返回字符串数组 Mid(str,n,m) 返回字符串第n个位置的m个字符 UBound(arr) 返回数组长度 Len(str) 返回字符串长度 Join(arr,,) 返回用,连接数组元素的字符串 Rnd 返回0-1的随机数与Randomize配合使用 Eval 计算一个表达式的值并返回结果 Round(str,n) 四舍五入保留小数点后n位 VarType 检查变量类型
四、数组 定义数组 1Dim var(10) 2Dim var Redim var(10)
五、函数和过程 函数 Function 函数名() End Function 过程 Sub 过程名() End Sub Function和Sub的区别 Function执行后调用函数名可获得返回值而Sub没有返回值 调用过程可用两种方式当用第2种时应省略括号 1Call 函数(参数1参数2...) 2函数 参数1参数2...
六、传值ByVal和传地址ByRef
Dim a,b
a1
b2
SetValue a,b
WScript.Echo a,b
Sub setValue(ByVal c, ByRef d)
c4
d5
End Sub
输出结果1,5 使用传址引用可修改变量的值而传值引用不会修改变量的值 默认参数不加ByVal则默认为ByRef
七、操作文件 定义句柄 Dim Var Set VarCreateObject()
1.1读txt文件
Dim fso,file,str
Set fsoCreateObject(Scripting.FileSystemObject)
Set filefso.OpenTextFile(E:\class\readtxt.txt)
Do Until file.AtEndOfStream
strfile.ReadLine
Loop
Set fileNothing
Set fsoNothing
1.2写txt文件
Set filefso.CreateTextFile(E:\class\writetxt.txt)
file.WriteLine Hello!
2.1读excel文件
Dim xlsApp,wkBook,wkSheet,content
Set xlsAppCreateObject(Excel.Application)
Set wkBookxlsApp.Workbooks.Open(E:\class\readexcel.xlsx)
Set wkSheetwkBook.Worksheets(Sheet1)
For i1 To rowCount
contentwkSheet.cells(i,1)
Next
wkBook.Close
xlsApp.Quit
Set wkSheetNothing
Set wkBookNothing
Set xlsAppNothing
2.2写excel文件
wkSheet.cells(i,5)content
wkBook.Save
3.1读DB 新建扩展名为.udl的文件双击打开数据属性窗口设置OLE驱动和数据源 用记事本打开.udl文件复制Provider这句话作为strCnn
Dim Cnn,Rst,strCnn
Set CnnCreateObject(ADODB.Connection)
Set RstCreateObject(ADODB.Recordset)
strCnnProviderMicrosoft.ACE.OLEDB.12.0;Data Sourcee:\class\calc.mdb;Persist Security InfoFalse
Cnn.Open strCnn
Rst.Open Select * from calc,Cnn
Rst.MoveFirst
Do While Not Rst.EOF
MsgBox Trim(Rst.Fields(TestNumber1))
Rst.MoveNext
Loop
Rst.Close
Cnn.Close
Set RstNothing
Set CnnNothing
3.2写DB
Set rstupdateCreateObject(ADODB.Recordset)
rstupdate.open update calc set decisflag, conn
rstupdate.Close
Set rstupdateNothing
4.1读xml
Dim xmlDoc,xmlRoot,xmlChildItem,msg
Set xmlDocCreateObject(Microsoft.XMLDOM)
xmlDoc.load E:\class\calc.xml
Set xmlRootxmlDoc.documentElement
Set xmlChildItemxmlRoot.firstChild
For Each xmlChildItem In xmlRoot.childNodes
Next
Set xmlChildItemNothing
Set xmlRootNothing
Set xmlDocNothing