function | description |
---|
CDate | Converts a valid date and time expression to a Date type. |
Date | Returns the current system date. |
DateAdd | Returns the date on which the specified time interval has been added. |
DateDiff | Returns the number of intervals between two dates. |
DatePart | Returns the specified part of the given date. |
DateSerial | Returns the date of the specified year, month, and day. |
DateValue | Returns the date. |
Day | Returns a number (between and including 1 to 31) representing the day of the month. |
FormatDateTime | Returns an expression formatted as a date or time. |
Hour | Returns a number representing the hour of the day (between and including 0 to 23). |
IsDate | Returns a Boolean value that indicates whether a calculated expression can be converted to a date. |
Minute | Returns a number representing the minute of the hour (between and including 0 to 59). |
Month | Returns a number representing the month of the year (between and including 1 to 12). |
MonthName | Returns the name of the specified month. |
Now | Returns the current system date and time. |
Second | Returns a number representing the seconds of a minute (between and including 0 to 59). |
Time | Returns the current system time. |
Timer | Returns the number of seconds since 12:00 AM. |
TimeSerial | Returns the time for a specific hour, minute, and second. |
TimeValue | time of return. |
Weekday | Returns a number representing the days of the week (between and including 1 to 7). |
WeekdayName | Returns the day of the week for the specified day of the week. |
Year | Returns a number representing the year. |
function | description |
---|
Asc | Converts the first letter in a string to an ANSI character code. |
CBool | Converts an expression to a Boolean type. |
CByte | Converts an expression to a byte type. |
CCur | Converts an expression to currency. |
CDate | Converts a valid date and time expression to a Date type. |
CDbl | Converts an expression to a double type. |
Chr | Converts the specified ANSI character code to a character. |
CInt | Converts an expression to an integer type. |
CLng | Converts an expression to a Long type. |
CSng | Converts an expression to a single precision type. |
CStr | Converts an expression to a String type. |
Hex | Returns the hexadecimal value of the specified number. |
Oct | Returns the octal value of the specified number. |
function | description |
---|
Abs | Returns the absolute value of the specified number. |
Atn | Returns the arctangent of the specified number. |
Cos | Returns the cosine of the specified number (angle). |
Exp | Returns the power of e (the base of natural logarithms). |
Hex | Returns the hexadecimal value of the specified number. |
Int | Returns the integer part of the specified number. |
Fix | Returns the integer part of the specified number. |
Log | Returns the natural logarithm of the specified number. |
Oct | Returns the octal value of the specified number. |
Rnd | Returns a random number less than 1 but greater than or equal to 0. |
Sgn | Returns an integer indicating the sign of the specified number. |
Sin | Returns the sine of a specified number (angle). |
Sqr | Returns the square root of the specified number. |
Tan | Returns the tangent of the specified number (angle). |
function | description |
---|
InStr | Returns the position where a string first appears in another string. The search starts at the first character of the string. |
InStrRev | Returns the position where a string first appears in another string. The search starts at the last character of the string. |
LCase | Converts the specified string to lowercase. |
Left | Returns the specified number of characters from the left side of the string. |
Len | Returns the number of characters in a string. |
LTrim | Remove the spaces to the left of the string. |
RTrim | Remove the spaces to the right of the string. |
Trim | Remove spaces to the left and right of the string. |
Mid | Returns the specified number of characters from a string. |
Replace | Replaces the specified part of the string a specified number of times with another string. |
Right | Returns the specified number of characters from the right side of a string. |
Space | Returns a string consisting of the specified number of spaces. |
StrComp | Compares two strings and returns a value representing the result of the comparison. |
String | Returns a string containing repeated characters of the specified length. |
StrReverse | Reverses a string. |
UCase | Converts the specified string to uppercase. |
function | description |
---|
CreateObject | Creates an object of the specified type. |
Eval | Evaluates the expression and returns the result. |
GetLocale | Returns the current locale ID. |
GetObject | Returns a reference to the automation object in the file. |
GetRef | Allows you to connect a VBScript subroutine to a DHTML event on the page. |
InputBox | Displays a dialog box where the user can enter text and / or click a button and then return to the content. |
IsEmpty | Returns a Boolean value that indicates whether the specified variable has been initialized. |
IsNull | Returns a Boolean value that indicates whether the specified expression contains invalid data (Null). |
IsNumeric | Returns a Boolean value that indicates whether the specified expression can be evaluated as a number. |
IsObject | Returns a Boolean value that indicates whether the specified expression is an automation object. |
LoadPicture | Returns a picture object. For 32-bit platforms only. |
MsgBox | Display a message box, wait for the user to click a button, and return a value indicating which button the user clicked. |
RGB | Returns a number representing the RGB color value. |
Round | Round the number. |
ScriptEngine | Returns the scripting language in use. |
ScriptEngineBuildVersion | Returns the build number of the scripting engine in use. |
ScriptEngineMajorVersion | Returns the major version number of the scripting engine in use. |
ScriptEngineMinorVersion | Returns the minor version number of the scripting engine in use. |
SetLocale | Sets the locale ID and returns the previous locale ID. |
TypeName | Returns the subtype of the specified variable. |
VarType | Returns a value indicating the subtype of the variable. |
VBScript can be used to automate repetitive Windows operating system tasks. In the Windows operating system, VBScript can run within the scope of Windows Script Host. The Windows operating system can automatically recognize and execute * .VBS and * .WSF file formats. In addition, Internet Explorer can execute HTA and CHM file formats. VBS and WSF files are completely textual, and they can only communicate with users through a few dialog windows. HTA and CHM files use HTML format, and their program code can be edited and inspected like HTML. VBScript and JavaScript code can be arbitrarily mixed in WSF, HTA and CHM files. HTA files are actually HTML files with VBS and JavaScript components. The CHM file is an online help, and users can edit the HTML program to CHM using a special editing program. VBScript
VBScript web browser
The VBS in the webpage can be used to direct the client's web browser (the browser executes the VBS program). VBS and JavaScript are competitors in this respect. They can be used to implement dynamic HTML, and even integrate entire programs into web pages. So far VBS has not been dominant in terms of customers, because it is only supported by Microsoft Internet Explorer (Mozilla Suite can support VBS by installing an external plug-in). JavaScript is supported by all web browsers. VBS and JavaScript use the same permissions in Internet Explorer, and they can only use objects in the Windows operating system to a limited extent.
VBScript web server
In terms of web servers, VBS is part of Microsoft's Active Server Pages, which competes with JavaServer Pages and PHP. Here VBS program code is directly embedded in the HTML page, such a web page ends with ASP. The web server Internet information service executes the program parts in the ASP page and converts the results into HTML and passes it to the web browser for use by the user. In this way, the server can hear the database and put the results into HTML pages.
VBScript data type
VBScript has only one data type, called a Variant. Variant is a special data type that can contain different categories of information depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type of the return values of all functions in VBScript.
the simplest
The simplest Variant can contain numeric or string information. Variant is treated as a number when used in a number context and as a string when used in a string context. That is, if you use data that looks like a number, VBScript assumes that it is a number and processes it in a way that works for numbers. Similarly, if the data used is only possible as a string, VBScript will treat it as a string. You can also include numbers in quotes ("") to make them strings.
Subtype
In addition to simple numbers or strings, Variants can further distinguish the specific meaning of numeric information. For example, use numeric information to represent a date or time. When such data is used with other date or time data, the results are always expressed as a date or time. From Boolean values to floating-point numbers, numeric information is varied. Variant contains types of numeric information called subtypes. In most cases, you can put the required data into a Variant, and Variant will operate in the way that works best for the data it contains.
description
Empty Uninitialized Variant. For numeric variables, the value is 0; for string variables, the value is a zero-length string ("").
Null Variant does not contain any valid data.
Boolean contains True or False.
Byte contains an integer between 0 and 255.
Integer contains integers between -32,768 and 32,767.
Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long contains integers between -2,147,483,648 and 2,147,483,647.
Single contains single-precision floating-point numbers with negative numbers ranging from -3.4402823E38 to -1.401298E-45, and positive numbers ranging from 1.401298E-45 to 3.402823E38.
Double contains double-precision floating-point numbers with negative numbers ranging from -1.79 769 31348 6232E308 to -4.9406564 5841247E-324 and positive numbers ranging from 4.9406564 5841247E-324 to 1. 7976931 3486232E308.
Date (Time) contains numbers representing dates ranging from January 1, 100 AD to December 31, 9999 AD.
String contains variable-length strings with a maximum length of 2 billion characters.
Object contains objects.
Error contains the error number.
VBScript error code
Microsoft VBScript compiler error error `` missing statement
ActiveServerPages, ASP0126 (0x80004005)-> Cannot find include file
MicrosoftOLEDBPRoviderforODBCDrivers (0x80040E21)-> SQL statement error (data type mismatch or table name (field name) error or table is in editing state, or the table does not exist in the database opened by conn)
MicrosoftOLEDBPRoviderforODBCDrivers (0x80040E14)-> SQL statement error (field name error, or data type mismatch)
MicrosoftOLEDBPRoviderforODBCDrivers (0x80040E07)-> SQL statement error (the type of the field to be inserted or updated does not match the variable data type)
MicrosoftOLEDBPRoviderforODBCDrivers (0x80040E57)-> SQL statement error (data to be inserted or updated overflow
MicrosoftOLEDBPRoviderforODBCDrivers (0x80040E10)-> SQL statement error (update field name or data type to be updated is wrong)
MicrosoftOLEDBPRoviderforODBCDrivers (0x80004005)-> SQL statement error (the value of the field to be inserted or updated cannot be null)
MicrosoftOLEDBPRoviderforODBCDrivers (0x80004005)-> Error opening database, no database found in specified directory
MicrosoftOLEDBPRoviderforODBCDrivers (0x80040E37)-> No table found
MicrosoftVBscript runtime error (0x800A000D)-> incorrect reference to rs variable (rs object is closed or undefined)
Microsoft VBscript runtime error (0x800A01C2)-> vbscript script error (vbscript statement error)
Microsoft VBscript runtime error (0x800A0006)-> vbscript script error (overflow error)
MicrosoftVBscript compiler error (0x800A040E)-> missing loop
MicrosoftVBscript compiler error (0x800A03EA)-> missing if or endif
MicrosoftVBscript compiler error (0x800A03EE)-> statement does not end (missing ")")
Microsoft VBscript compiler error (0x800A03F6)-> if statement error (missing endif)
MicrosoftVBscript runtime error (0x800A005B)-> missing set
MicrosoftVBscript runtime error (0x800A0005)-> variable is not defined
Microsoft VBscript compiler error (0x800A03F9)-> if statement is missing then
Microsoft VBscript compiler error (0x800A0411)-> dim statement definition error
Microsoft VBscript compiler error (0x800A0408)-> sql statement error (?????????????????)
Microsoft VBScript runtime error (0x800A01B6) Reason: set rs = server.create ... you are missing set
ADODB.Recordset (0x800A0BB9)-> SQL statement error (SQL statement or conn statement is undefined or an error occurred when assigning an rs attribute)
ADODB.Recordset (0x800A0CC1)-> rs object error (rs object does not exist or incorrectly references a non-existing field name)
ADODB.Recordset (0x800A0BCD)-> rs object error
ADODB.Recordset (0x800A0E78)-> rs object error (Recordset does not exist, missing rs.open statement)
ADODB.Recordset (0x800A0CC1)-> rs object error (referenced a non-existing field name)
ADODB.Recordset (0x800A0E7D)-> conn definition error
ADODB.Recordset (0x800A0CB3)-> The database is opened as read-only, and data cannot be updated
VBScript syntax error
If the VBScript statement structure violates one or more VBScript scripting language syntax rules, a VBScript syntax error is generated.
Errors usually occur when the program is compiled before the program is executed. Here are 53 syntax errors:
Error number description
Decimal Hex Description
1001 800A03E9 Out of memory
1002 800A03EA Syntax error
1003 800A03EB Missing ":"
1005 800A03ED requires '('
1006 800A03EE requires ')'
1007 800A03EF Missing "]"
1010 800A03F2 identifier required
1011 800A03F3 requires '='
1012 800A03F4 requires 'If'
1013 800A03F5 requires 'To'
1014 800A03F6 requires 'End'
1015 800A03F7 requires 'Function'
1016 800A03F8 requires 'Sub'
1017 800A03F9 requires 'Then'
1018 800A03FA requires 'Wend'
1019 800A03FB requires 'Loop'
1020 800A03FC requires 'Next'
1021 800A03FD requires 'Case'
1022 800A03FE requires 'Select'
1023 800A03FF expression required
1024 800A0400 required statement
1025 800A0401 End of statement required
1026 800A0402 requires integer constant
1027 800A0403 requires 'While' or 'Until'
1028 800A0404 requires 'While,', 'Until,' or the statement does not end
1029 800A0405 requires 'With'
1030 800A0406 identifier is too long
1031 800A0407 Invalid number
1032 800A0408 Invalid character
1033 800A0409 unterminated string constant
1034 800A040A open comment
1037 800A040D Invalid use of keyword 'Me'
1038 800A040E 'loop' without 'do'
1039 800A040F Invalid 'exit' statement
1040 800A0410 Invalid 'for' loop control variable
1041 800A0411 Name redefinition
1042 800A0412 must be the first statement of the line
1043 800A0413 Cannot be assigned to non-Byval parameters
1044 800A0414 Parentheses cannot be used when calling Sub
1045 800A0415 requires literal constant
1046 800A0416 requires 'In'
1047 800A0417 'Class' required
1048 800A0418 must be defined inside a class
1049 800A0419 Let, Set or Get is required in the property declaration
1050 800A041A requires 'PRoperty'
1051 800A041B The number of parameters must be consistent with the attribute description
1052 800A041C Cannot have multiple default properties / methods in a class
1053 800A041D Class initialization or termination can not take parameters
1054 800A041E PRoperty Let or Set should have at least one parameter
1055 800A041F Unwanted 'Next'
1056 800A0420 'Default' can only be specified on 'PRoperty' or 'Function' or 'Sub'
1057 800A0421 says 'Default' must also say 'Public' "
1058 800A0422 'Default' can only be specified in PRoperty Get
VBScript running error
If a VBScript script performs an operation that the system cannot perform, it will generate a VBScript runtime error. Only when running a script, assigning a value to a variable expression, or
VBScript runtime errors occur only when memory is allocated. Here are 65 runtime errors:
Error number description
Decimal Hex Description
5 800A0005 invalid procedure call or parameter
6 800A0006 Overflow
7 800A0007 Out of memory
9 800A0009 Subscript out of bounds
10 800A000A The array is fixed-length or temporarily locked
11 800A000B divided by zero
13 800A000D type mismatch
14 800A000E string space overflow
17 800A0011 The requested operation cannot be performed
28 800A001C Stack overflow
35 800A0023 Sub or Function is not defined
48 800A0030 Load DLL error
51 800A0033 Internal error
52 800A0034 Bad file name or number
53 800A0035 File not found
54 800A0036 Bad file mode
55 800A0037 The file is already open
57 800A0039 Device I / O error
58 800A003A file already exists
61 800A003D disk space is full
62 800A003E Input exceeds end of file
67 800A0043 Too many files
68 800A0044 Device is not available
70 800A0046 Permission disabled
71 800A0047 Disk is not ready
74 800A004A Cannot rename with a different drive
75 800A004B Path / file access error
76 800A004C Path not found
91 800A005B Object variable is not set
92 800A005C For loop is not initialized
94 800A005E Illegal use of Null
322 800A0142 The required temporary file cannot be created
424 800A01A8 Object required
429 800A01AD ActiveX component cannot create object
430 800A01AE class does not support automation
432 800A01B0 File name or class name not found in automated operation
438 800A01B6 Object does not support the property or method
440 800A01B8 Automation error
445 800A01BD object does not support this operation
446 800A01BE object does not support the specified parameter
447 800A01BF object does not support the current locale
448 800A01C0 named parameter not found
449 800A01C1 parameter is not selectable
450 800A01C2 Incorrect parameter number or invalid parameter attribute value
451 800A01C3 object is not a collection
453 800A01C5 The specified dll function was not found
455 800A01C7 Code source lock error
457 800A01C9 This key is already an element association of this set
458 800A01CA variable uses an Automation type that is not supported in VBScript
462 800A01CE remote server does not exist or cannot be accessed
481 800A01E1 invalid picture
500 800A01F4 Variable is undefined
501 800A01F5 illegal distribution
502 800A01F6 script object is not secure
503 800A01F7 Object cannot be safely initialized
504 800A01F8 Object cannot be created safely
505 800A01F9 Invalid or unqualified reference
506 800A01FA class is not defined
507 800A01FB An error occurred
5016 800A1398 requires regular expression object
5017 800A1399 Syntax error in regular expression
5018 800A139A Wrong quantifier
5019 800A139B ']' is required in regular expression
5020 800A139C ')' is required in regular expression
5021 800A139D character set out of bounds
32811 800A802B element not found
VBScript script
What is VBScript
VBScript is a scripting language
Scripting language is a lightweight programming language
VBScript is a lightweight version of Microsoft's programming language Visual Basic
how to work
When VBScript is inserted into an HTML document, the Internet browser reads the document and interprets the VBScript. VBScript may be executed immediately or at a later event.
Read VBScript
<html>
<head>
</ head>
<body>
<scripttype = "text / vbscript">
document.write ("HellofromVBScript!");
</ script>
</ body>
</ html>
Variable name rules
Must start with a letter
Cannot contain period (.)
Cannot exceed 255 characters
Conditional statements
Often, when we write code, we need to perform different operations based on different judgments. We can do this using conditional statements.
In VBScript we can use three conditional statements:
if statement If you want to execute a series of code when the condition is true, you can use this statement.
if ... then ... else statement Use this statement if you want to execute one of two sets of code.
if ... then ... elseif statement Use this statement if you want to choose one of multiple sets of code to execute.
select case statement Use this statement if you want to select one of multiple sets of code to execute.
example
If .... Then ..... Else
You can use If ... Then ... Else statements in the following situations:
When the condition is true, execute a piece of code
When selecting one of two pieces of code to execute
If you need to execute only one statement when the condition is true, you can write the code as one line:
Ifi = 10ThenMsgbox "Hello"
In the code above, there is no .else .. statement. We just let the code perform an action when the condition is true (when i is 10).
If we need to execute more than one statement when the condition is true, then we must write a statement on a line and then use the keyword "End If" to end the statement:
Ifi = 10ThenMsgbox "Hello" i = i + 1EndIf
In the code above, there is also no .else .. statement. We just let the code perform multiple operations when the condition is true.
If we want to execute a statement when the condition is true and another statement when the condition is not true, we must add the keyword "Else":
Ifi = 10Then
Msgbox "Hello"
Else
Msgbox "Goodbye"
EndIf
The first piece of code is executed when the condition is true, and the second piece of code is executed when the condition is not true (when i is not equal to 10).
If .... Then ..... Elseif
If you want to choose one of multiple sets of code to execute, you can use if ... then ... elseif statements:
Ifpayment = "Cash" Then
Msgbox "Youaregoingtopaycash!"
ElseIfpayment = "Visa" Then
Msgbox "Youaregoingtopaywithvisa."
ElseIfpayment = "AmEx" Then
Msgbox "YouaregoingtopaywithAmericanExpress."
Else
Msgbox "Unknownmethodofpayment."
EndIf
Select Case
If you want to select one of multiple sets of code to execute, you can use the SELECT statement:
SelectCasepayment
Case "Cash"
Msgbox "Youaregoingtopaycash"
Case "Visa"
Msgbox "Youaregoingtopaywithvisa"
Case "AmEx"
Msgbox "YouaregoingtopaywithAmericanExpress"
CaseElse
Msgbox "Unknownmethodofpayment"
EndSelect
The above code works: First, we need a simple expression (often a variable), and this expression will be evaluated once. The value of the expression is then compared with the value in each case. If they match, the code corresponding to the matched case is executed.
VBScript system management example
use
WSHFileSystemObject VBScript WSH's FileSystemObject manages drives and files
Enumerate the drives:
SetobjFSO = CreateObject ("Scripting.FileSystemObject") SetcolDrives = objFSO.DrivesForEachobjDriveincolDrivesWscript.Echo "Driveletter:" & objDrive.DriveLetterNext
Delete Files:
SetobjFSO = CreateObject ("Scripting.FileSystemObject") objFSO.DeleteFile ("C: \ FSO \ ScriptLog.txt")
WMI VBScript uses WMI to manage computers
View the remaining space of the c drive
SetobjWMIService = GetObject ("winmgmts:") SetobjLogicalDisk = objWMIService.Get ("Win32_LogicalDisk.DeviceID = 'c:'") Wscript.EchoobjLogicalDisk.FreeSpace
View services
SetcolServiceList = GetObject ("winmgmts:"). ExecQuery ("SELECT * FROM" _ & "Win32_ServiceWHEREState = 'Stopped'ANDStartMode =' Auto '")
ADSI VBScript uses ADSI to manage domains
Read server members in OU
SetobjGroup = GetObject ("LDAP: // cn = Atl-Users, ou = HR, dc = NA, dc = fabrikam, dc = com") ForEachMemberinobjGroup.GetEx ("member") Wscript.EchoMemberNext
Read the URL and phone number of the user account
SetobjGroup = GetObject ("LDAP: // cn = MyerKen, ou = HR, dc = NA, dc = fabrikam, dc = com") ForEachurlinobjGroup.GetEx ("url") Wscript.EchourlNextForEachotherTelephoneinobjGroup.GetEx ("otherTelephone") Wscript. EchootherTelephoneNext
VBScript pros and cons
VBScript advantages
Since VBScript is interpreted and executed by a web browser, there is no need to increase the load on the server.
Easy to learn.
All Windows versions after 2000 / 98SE can be used directly.
You can use other programs and available items (especially Microsoft Office).
VBScript disadvantages
VBS cannot now be attached to emails. Microsoft Outlook refuses to accept VBS as an attachment, and the recipient cannot directly use the VBS attachment.
VBS's various editors are not welcome.
The operating system does not have any special protection facilities. VBS programs are treated the same as other JS, EXE, BAT, or CMD programs. The operating system does not have the ability to monitor malicious functions.