Variant ---VBScript中唯一的數(shù)據(jù)類型,VB并不支持用戶定義類型User Defined Type,UDT)
1 子類型的檢查和類型轉(zhuǎn)換
TypeName() 返回文本形式的類型
VarType() 返回數(shù)字形式的子類型
匈牙利表示法
var --- Variant
str --- 字符創(chuàng) String
int ----整形 Integer
lng ----長整形 long
byt ——單字節(jié) byte
sng——單精度浮點數(shù)Single
dbl——雙精度浮點數(shù)double
cur——貨幣(Currency)
obj——對象(Object)
Bool——布爾
Is函數(shù): IsNumber, IsDate, IsError
Empty:未初始化, IsEmtpy(), if( varTest = Empty) then
NULL:空值, IsNull()
避免因NULL之產(chǎn)生問題: strCustomerName=""& rsCustomers.Fields("Name").Value
Dim objFSO
set objFSO = WScript.CreateObject(“Scripting.FileSystemObject“)
set objFSO = nothing
數(shù)組:
Dim astrPhonelist()
Redim Preserve AstrPhonelist(2,1)
UBound(astrPhonelist,2) 行數(shù) UBound(astrPhonelist,1) 列數(shù)
Erase astrPhoneList 清除數(shù)組對于靜態(tài)數(shù)組, 刪除數(shù)組對于動態(tài)數(shù)組。
過程及函數(shù)
調(diào)用過程的合法方式
調(diào)用過程的非法方式
Comments
GreetUser “Bill”
GreetUser(“Bill”)
不可以加括號
Call GreetUser(“Bill”)
Call GreetUser “Bill”
加Call一定要加括號
調(diào)用函數(shù)的合法方式
調(diào)用函數(shù)的不合法方式
lngSum = AddNumbers(10,20)
lngSum = AddNumbers 10,20
要獲得函數(shù)的返回值,就不能用Call關(guān)鍵字,并且一定要將參數(shù)放在圓括號中。沒有圓括號是非法的。
Call AddNumbers(10,20)
lngSum = Call AddNumbers(10,20)
加Call一定要加括號
AddNumbers 10, 20
AddNumbers(10,20)
可以同時忽略call和括號。
2. QTP
WScript properties and methods
QuickTest
Not supported
WScript.Application property
Not supported
WScript.Arguments
Not supported
Use instead the Parameter or TestArgs object
WScript.FullName property
Not supported
WScrip.Name property
Not supported
use instead ScriptEngine Function
WScript.Path property
Not supported
Add following code to an associated external vbs
Arr = Split(Environment(”TestDir”),”\”)
Redim Preserve arr(UBound(arr)-1)
Environment(“TestPath”)= Join(arr,”\”)
WScript.ScriptFullName property
Not supported
use instead environment(“TestDir”)
WScript.ScriptName property
Not supported
environment(“TestCase”)
WScript.StdErr, StdIn, Std Out properties
Not supported
WScript.Version property
Not supported
user instead a concatenation of ScriptEngineMajorVersion Function, ScriptEngineMinorVersion function.
WScript.CreateObject method
CreateObject function
WScript.ConnectObject method
Use instead ConnectObject function.
WScript.eaho
msgbox
WScript.GetObject
Getobject
WScript.ShowUsage
WScript.Sleep
wait
WshArguments collection object
WshName
WshUnName