Upload
prooving-proof
View
222
Download
0
Embed Size (px)
Citation preview
7/31/2019 VBScript Commands and Functions
1/5
Loquehayadespusdecomillaseignora
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
ARRAYSANDVARIABLES
indexnumber(0-length)Variablescanhavealocal(functionsandsubs)orglobal(mainbody)scope
OptionExplicit Thisshowsanerrormessageifyouuseavariablewithoutdeclaringitbefore.
Dimvar(length) (itcanbedeclaredwithoutaspecificlength)ReDim[preserve]varname(subscripts) (ifit'swrittenpreserve,previousvarnamevaluesaresaved)
public/privatevar1,var2,... Youcanexplicitlydeclareglobal/localvariablesbywrittingthis
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
DATATYPES
Numeric Integer,Double
String ""Date #1/3/2002# #January3,2001# #3January,2001# #January3,200122:30:10#Time #22:30:10# #10:30:10PM#Boolean
AUTOMATICCONVERSION
Number+or- StringIfthestringrepresentsanumber,itisconvertedtoanumberandtheresultisanumber.Otherwise,theprogramstopswithanerrormessageDate/time+or-NumberThewhole(integer)partofthenumberisaddedtothed
ateasanumberofdays.Anyfractionalpartofthenumberisaddedasatimeoffset,asafractionofaday.Date+or- StringIfthestringrepresentsanumber,itisconvertedtoanumberandtheresultisadate.Otherwise,anerroroccurs.Anything&Anything Valuesofanytypeareconvertedtostrings,andthestringsareconcatenated.
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
7/31/2019 VBScript Commands and Functions
2/5
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
CONSTANTS
constvariable=value variablenopuedecambiaralolargodelprograma
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
OPERATORS
Notequaltois Objectequivalence& Stringconcatenation(anytypeofvalue)(sometimes+canalsobeused)Mod Modulus>= Greaterthanorequal
not Negationnot (3=4)-True
and Conjunction (3=4)and(3
7/31/2019 VBScript Commands and Functions
3/5
_____________________________________________________________________________
FUNCTIONS
Ifwearen'tusingthevaluewhichafunctionisgoingtogiveus,oriffunctiondoesn'tneedanyargument -> wedon'tneedtowriteparentheses
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
[PROCEDURES:FUNCTIONSANDSUBROUTINES(subroutinesdoesn'treturnvalues)]
functionname(arguments)statementsendfunctionsubname(arguments)statementsendsub
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
[DATEANDTIME]
Date()andTime() ThedateisstoredasanintegernumberofdayssinceJanuary1,0099,andtimesarestoredasdecimalfractionsofaday(1secondequals0.0000115741)Youcanoperatethemasintegers.DateAdd(interval,number,date) ItaddstimetoagivendateDateDif(interval,date1,date2) Itgivesthenumberof"interval"betweentwodatesDay(date) Thedayofthemonthofthegivendatefrom1to31.Weekday(date) Thedayoftheweekofthegivendateasanumberfrom1to7,where1equalsSunday,2equalsMonday,andsoon.
Month(date) Themonthofthegivendate,where1equalsJanuaryandsoon.WeekdayName(date) Thedayoftheweekofdateasastring.MonthName(date) Thenameofthemonthinwhichdatefalls.Hour(time) Thehour(0to23)ofthegiventime.Minute(time) Theminute(0to59)ofthegiventime.Second(time) Thesecond(0to59)ofthegiventime.Date(time) Withanargument,Datereturnsjustthedatepartofadate/timevalue,effectively,midnightofthespecifieddate.(Withoutanargument,Datereturnstodaysdate).Time(time) Withanargument,Timereturnsjustthetimepartofadate/timevalue.(Withoutanargument,Timereturnsthecurrentt
ime).Now() Currentdate-time
-Interval-
YYYYYears MMonths DDays NMinutesQQuarters WWeeks HHours SSeconds
7/31/2019 VBScript Commands and Functions
4/5
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
[STRING-MANIPULATION]
InStr(n,filename,.DAT) 0ifthereisnothingbefore".DAT"andit'sthenumberofcharacterwhere".DAT"startsifthereisit(WithTEST.DAT,itwouldgiveus5)Thisfunctioniscasesensitive.Itstartssearchingfromcharn.InStrRev(ABCABC,AB) Itdoesthesameasbeforebutstartingthesearchfromtheright
Len(string) ThelengthofstringincharactersLcase(string) lowercaseUcase(string) uppercaseTrim(string) leadingandtrailingspacesremovedLtrim(string) leadingspacesremovedRtrim(string) trailingspacesremoved
-Extractingcharacters-
Left(string,length) TheleftmostlengthcharactersfromstringRight(string,length) TherightmostlengthcharactersfromstringMid(string,start) ThatpartofstringfromcharacterpositionstartonwardMid(string,start,length) lengthcharactersofstringfrompositionstart
-Convertingstring-
cstr(value) Astringrepresentationofvalue.clng(value) stringtoalong(32-bit)integer.
cdbl(value) toadouble-precisionfloatingpointvalue.cdate(value) toadate-timevalue.chr(value) Returnsaone-characterstringcontaingthecharactercorrespondingtotheintegerASCIIvalue.asc(string) ReturnstheASCIIvalueofthefirstcharacterinthestring.
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
[I/O]
-MsgBox-
MsgBox("msg",buttons(+type),title) Scriptsecuencedoesn'tworkuntilyouclickthebutton
BUTTONS:
7/31/2019 VBScript Commands and Functions
5/5
VbOKOnly 0 OKbuttonVbOKCancel 1 OKandCancelbuttonsVbAbortRetryIgnore 2 Abort,Retry,andIgnorebuttonsVbYesNoCancel 3 Yes,No,andCancelbuttonsVbYesNo 4 YesandNobuttonsVbRetryCancel 5 RetryandCancelbuttons
TYPE:
VBCritical 16 CriticalMessageiconVBQuestion 32 QuestioniconVbExclamation 48 ExclamationiconVBInformation 64 Informationicon
RETURN:
VbOK 1VbCancel 2VbAbort 3vbRetry 4vbIgnore 5VbYes 6VbNo 7
-InputBox-
InputBox(msg,title,defaultinbox) Valuegivenbyusercanbeusedeithernumberorstring
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
_____________________________________________________________________________
ERRORHANDLING
onerrorresumenext Fileisexecuteddespiteerrors(secondtimeitiswrittenitrestoresdefaultbehaviour(stopsifthereissomeerror))
err.numbererr.description