??????????QTP?г????VBS????
?????????? ???????[ 2010/2/20 13:42:23 ] ????????
Left ????
???? Variant (String)?????а?????????д??????????????????????
??
Left(string?? length)
Left ?????????????????????????
???? ???
string ????????????????????????????Щ??????????????? string ???? Null???????? Null??
length ?????????? Variant (Long)????????????????????????????????? 0??????????????? ("")????????????? string ????????????????????????
???
??? string ???????????? Len ??????
??? LeftB ?????????????????????е????????????? length ?????????????????????????????????
Mid ????
????????з????????????????
Mid(string?? start[?? length])
????
string
??????????????з??????????? string ???? Null?????? Null??
Start
string ?б????????????????λ?á???? start ?????? string ????????????Mid ??????????????? ("")??
Length
???????????????????? length ???????????????????? start ???????????????????????д? start ??????????????????????
???
??ж? string ????????????????? Len ??????
???????????? Mid ??????????????д??????????????????????
Dim MyVar
MyVar = Mid("VB???is fun!"?? 4?? 6) ??MyVar ???? "scr??pt"??
??? MidB ?????????????????е?????????????á???????????????????????????????
Len ????
?????????????????????????洢?????????????????
Len(string | varname)
????
string
??????Ч???????????????? string ???????? Null?????? Null??
Varname
??????Ч???????????? varname ???????? Null?????? Null??
???
???????????? Len ??????????????е?????????
Dim MyString
MyString = Len("VBscr??pt") ??MyString ???? 8??
??? LenB ?????????????????е?????????????á?LenB ?????????????е????????????????????????????????????
Right ????
??????????????????????????
Right(string?? length)
????
string
?????????????????????????????? string ?????а??? Null?????? Null??
Length
?????????????????????????????? 0???????????????????????????????? string ?????е????????????????????????????
???
???? string ?????е???????????? Len ??????
???????????? Right ??????????????????????????????
Dim AnyString?? MyStr
AnyString = "Hello World" ?? ???????????
MyStr = Right(AnyString?? 1) ?? ???? "d"??
MyStr = Right(AnyString?? 6) ?? ???? " World"??
MyStr = Right(AnyString?? 20) ?? ???? "Hello World"??
??? RightB ??????????????е?????????length ????????????????????????????????????
InStr ????
?????????????????????е???γ????λ?á?
InStr([start?? ]string1?? string2[?? compare])
????
start
????????????????????????????????λ?á?????????????????????λ????????????? start ???? Null??????????????????? compare?????????? start ??????
string1
?????????????????????????
string2
??????????????????????
compare
????????????????????????????????????й???????????????á?????????????????ж????????
????
compare ?????????????????
???? ? ????
vbBinaryCompare 0 ??ж????????
vbTextCompare 1 ??????????
?????
InStr ???????????????
??? InStr ????
string1 ????? 0
string1 ? Null Null
string2 ????? start
string2 ? Null Null
string2 ?????? 0
?? string1 ????? string2 ?????????????λ??
start > Len(string2) 0
???
???????????? InStr ???????????
Dim SearchString?? SearchChar?? MyPos
SearchString ="XXpXXpXXPXXP" ?? ??????????????
SearchChar = "P" ?? Search for "P".
MyPos = Instr(4?? SearchString?? SearchChar?? 1) ?? ??λ?? 4 ???е???????????? 6??
MyPos = Instr(1?? SearchString?? SearchChar?? 0) ?? ??λ?? 1 ???е????????????? 9??
MyPos = Instr(SearchString?? SearchChar) ?? ???????£????е????????????????????????????? 9??
MyPos = Instr(1?? SearchString?? "W") ?? ??λ?? 1 ???е????????????? 0??????? "W"????
??? InStrB ??????e???????????е????????????? InStrB ?????????????????????????????е???γ???????λ??????????λ?á?
LTrim??RTrim?? Trim ????
????????????? (LTrim)????????? (RTrim) ????????????? (Trim) ?????????????
LTrim(string)
RTrim(string)
Trim(string)
string ????????????Ч???????????????? string ?????а??? Null?????? Null??
???
???????????? LTrim?? RTrim?? ?? Trim ??????????????????????????β????? ?????β?????
Dim MyVar
MyVar = LTrim(" vbscr??pt ") ??MyVar ???? "vbscr??pt "??
MyVar = RTrim(" vbscr??pt ") ??MyVar ???? " vbscr??pt"??
MyVar = Trim(" vbscr??pt ") ??MyVar ???? "vbscr??pt"??
Rnd ????
??????????????
Rnd[(number)]
number ????????????????Ч???????????
???
Rnd ???????????С?? 1 ?????????? 0 ?????number ????????? Rnd ???????????????
??? number ? Rnd ????
С???? ??ζ???????????? number ????????
?????? ?????е?????????????
?????? ???????????
??? ?????е?????????????
?????????????? Rnd ??????????????е????????????????????????????????κγ??????????????????????????С?
????? Rnd ???????????????? Randomize ???????????????????????????????л?????????????????
??????????Χ???????????????????1????
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
???? upperbound ????Χ????磬?? lowerbound ????Χ?????硣
??? ??????????????У??????????????????? Randomize ???????????????????? Rnd???????? number ??? Randomize ????????????????????С?
Randomize ???
??????????????????
??
Randomize [number]
????? number ?????? Variant ???κ???Ч???????????
???
Randomize ?? number ?? Rnd ??????????????????????????????????????? number ????μ?????????????? number???????????????????????μ????????
????????? Randomize????????????Rnd ??????????ε??? Rnd ?????????????
??? ???????????????????У?????t???????????? Randomize ???????t??и???????? Rnd????t?????? number ??? Randomize ????????????????????е??
Rnd ???????
???????? Rnd ?????????????? 1 ?? 6 ???????????
??????? Randomize ?????????????????????????????????????? ???? Randomize ?? Timer ??????????????μ?????????????
Dim MyValue
Randomize ?? ???????????????????????????
MyValue = Int((6 * Rnd) + 1) ?? ???? 1 ?? 6 ????????????
Split????
????
????????±????????????飬???????????????????????
??
Split(expression[?? delimiter[?? count[?? compare]]])
Split??????????????????
???? ????
expression ????????????????????????????????? ?????expression??????????????????("")??Split????????????飬?????????????????顣
delimiter ???????????????????????????????????????????????????(" ")????????????delimiter????????????????????????????????????????????????? expression???????
count ????????????????????????1??????????е??????????
compare ?????????????????б??????????????????????????????????????????????
?????
compare??????????????£?
???? ? ????
vbUseCompareOption ?1 ??Option Compare????е????????б???
vbBinaryCompare 0 ??ж????????
vbTextCompare 1 ??????????
vbDatabaseCompare 2 ??????Microsoft Access?????????????????????б???
Replace ????
??????????????????????????????????滻???????????????
Replace(expression?? find?? replacewith[?? compare[?? count[?? start]]])
????
expression
????????????????????????????????
Find
?????????????????????
Replacewith
?????????滻???????????
Start
????expression ?п???????????????λ?á????????????? 1?????count ???????????
count
???????????????滻??????????????????? -1????????????п?????滻????? start ??????????á?
Compare
????????????????????????????????????й???????????????á????????????????? 0 ??????ζ???????ж????????
????
compare ?????????????????
???? ? ????
vbBinaryCompare 0 ??ж????????
vbTextCompare 1 ??????????
?????
Replace ???????????
??? Replace ????
expression ????? ????????? ("")??
expression ? Null ????
find ????? expression ???????
replacewith ????? expression ?????????????????????? find ??????????????
start > Len(expression) ???????????
count ? 0 expression ???????
???
Replace ????????????????滻?????? start ?????λ?????? expression ????????β?????????????????????????????????β???????
???????????? Replace ???????????????
Dim MyString
MyString = Replace("XXpXXPXXp"?? "p"?? "Y") ??????????????????????????? "XXYXXPXXY"??
MyString = Replace("XXpXXPXXp"?? "p"?? "Y"?? ?????????????????????????? "YXXYXXY"??3???? -1?? 1)
StrComp ????
??????????????????????????
StrComp(string1?? string2[?? compare])
????
string1
??????????Ч?????????????
string2
??????????Ч?????????????
Compare
????????????????????????????????????????????ж?????????й???????????????á??????
????
compare ?????????????????
???? ? ????
vbBinaryCompare 0 ??ж????????
vbTextCompare 1 ??????????
?????
StrComp ?????????·??????
??? StrComp ????
string1 С?? string2 -1
string1 ???? string2 0
string1 ???? string2 1
string1 ?? string2 ? Null Null
???
???????????? StrComp ??????????????????????????????????? 1 ???????????????????????? 0 ?????????ж????????
Dim MyStr1?? MyStr2?? MyComp
MyStr1 = "ABCD": MyStr2 = "abcd" ???????????
MyComp = StrComp(MyStr1?? MyStr2?? 1) ?? ???? 0??
MyComp = StrComp(MyStr1?? MyStr2?? 0) ?? ???? -1??
MyComp = StrComp(MyStr2?? MyStr1) ?? ???? 1??
CInt ????
????????????????????? Integer ??????? Variant??
CInt(expression)
expression ????????????Ч???????
???
???????????????????????????д??????????Щ??????????????????????????????????????????????磬??????????????????????????????£???? CInt ?? CLng ??????????????
CInt ??????????д?????????????? Integer ?????????????????????????????????????????????????????????????????????á?
??? expression ?? Integer ????????????Χ???????????
???????????? CInt ??????????? Integer:
Dim MyDouble?? MyInt
MyDouble = 2345.5678 ?? MyDouble ?? Double??
MyInt = CInt(MyDouble) ?? MyInt ???? 2346??
??? CInt ????? Fix ?? Int ????????????С?????????????????????????????С????????????? 0.5 ??? CInt ????????????????????????????????磬 0.5 ????????? 0?? ??? 1.5 ????????? 2.
CStr ????
????????????????????? String ??????? Variant??
CStr(expression)
expression ????????????Ч???????
???
???????????????????????????д??????????Щ??????????????????????????????????????????????磬??? CStr ??????????? String??
CStr ??????????? Str ?????????д?????????????? String ???????????????????????????????????????????????????????á?
expression ?????±??????????????
??? expression ? CStr ????
Boolean ??????????? True ?? False??
Date ???????????????????????????
Null ?????????
Empty ????????? ("")??
Error ????????????????д?????????? Error??
??????? ??????????????????
???????????? CStr ?????????????? String:
Dim MyDouble?? MyString
MyDouble = 437.324 ?? MyDouble ??????????
MyString = CStr(MyDouble) ?? MyString ???? "437.324"??
LCase ????
???????????Сд?????
LCase(string)
string ????????????Ч???????????????? string ?????а??? Null?????? Null??
???
????д????????Сд?????????Сд???????????????????
???????????? LCase ???????д???????Сд?????
Dim MyString
Dim LCaseString
MyString = "VBscr??pt"
LCaseString = LCase(MyString) ?? LCaseString ???? "vbscr??pt"??
UCase ????
????????????д?????
UCase(string)
string ????????????Ч???????????????? string ?????а??? Null?????? Null??
???
???Сд???????????д????????д?д?????????????????????
???????????? UCase ????????????????д?????
Dim MyWord
MyWord = UCase("Hello World") ?? ????"HELLO WORLD"??
MsgBox ????
????????????????????????????????????????????????????????
MsgBox(prompt[?? buttons][?? title][?? helpfile?? context])
????
prompt
????????????????е????????????prompt ????????? 1024 ??????????????????????????????? prompt ?а???????У?????????????????? (Chr(13))?????з? (Chr(10)) ???????з?????? (Chr(13) & Chr(10)) ?????С?
Buttons
??????????????????????????????????????????????????????????????????????????????й???????????????á??????????????? buttons ??????? 0??
Title
???????????????е?????????????????? title??????ó???????????????????С?
Helpfile
?????????????????????????????????????????????????????? helpfile????????? context???? 16 λ??????????á?
Context
?????????????????????????????????????????????????????????????? context????????? helpfile???? 16 λ??????????á?
????
buttons ?????????????????
???? ? ????
vbOKOnly 0 ????????????
vbOKCancel 1 ????????????????
vbAbortRetryIgnore 2 ?????????????????????
vbYesNoCancel 3 ?????????????????
vbYesNo 4 ??????????
vbRetryCancel 5 ????????????????
vbCritical 16 ????????????
vbQuestion 32 ????????????
vbExclamation 48 ?????????????
vbInformation 64 ????????????
vbDefaultButton1 0 ????????????????
vbDefaultButton2 256 ????????????????
vbDefaultButton3 512 ?????????????????
vbDefaultButton4 768 ????????????????
vbApplicationModal 0 ??ó??????????????????????????????????ó????й?????
vbSystemModal 4096 ????????????????????????????ó?????????
?????? (0 - 5) ??????????????????????????????????????? (16?? 32?? 48?? 64) ???????????????????????? (0?? 256?? 512) ??????????????????????? (0?? 4096) ?????????????????????Щ????????????? buttons ?????????????????????????????
?????
MsgBox ?????????·??????
???? ? ???
vbOK 1 ???
vbCancel 2 ???
vbAbort 3 ????
vbRetry 4 ????
vbIgnore 5 ????
vbYes 6 ??
vbNo 7 ??
???
????????? helpfile ?? context???????????? F1 ??????????????????????????
????????????????????? ESC ???????????Ч??????????????????????????????????????????????????????????????????????????????????κ????
??MicroSoft Internet Explorer???MsgBox????????κζ???????????????"VBscr??pt"???????????????????????????
?????????????? MsgBox ???????÷???
Dim MyVar
MyVar = MsgBox ("Hello World!"?? 65?? "MsgBox Example")
?? MyVar ???? 1 ?? 2????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11