UNIDAD 1: VBSCRIPT ELEMENTOS BASICOS
TEMA APENDIC1D: VISUAL BASIC SCRIPT PALABRAS RESERVADAS
Category/Keyword
Type
Usage
Arithmetic
Atn
Function
Returns the arctangent of a number Atn(number)
Cos
Function
Returns the cosine of an angle Cos(number)
Exp
Function
Returns a number raised to a power Exp(number)
Log
Function
Returns the logarithm of a number Log(number)
Randomize
Statement
Primes the internal random number generator Randomize
Rnd
Function
Returns a random number Rnd
Sin
Function
Returns the sine of an angle Sin(number)
Sqr
Function
Returns the square root of a number Sqr(number)
Tan
Function
Returns the tangent of an angle Tan(number)
Array handling
Dim
Statement
Declares an array Dim arrayname([subscripts])
Erase
Statement
Clears the contents of an array Erase arrayname
IsArray
Function
Returns True if var is an array, and False if not IsArray(var)
Lbound
Function
In VBScript, always returns 0 Lbound(arrayname)
Preserve
Statement
Copies the contents of a dynamic array to a resized dynamic array Redim Preserve arrayname(subscripts)
ReDim
Statement
Declares a dynamic array or redimensions a dynamic array (see Preserve) ReDim arrayname() or ReDim arrayname([subscripts])
UBound
Statement
Returns the largest subscript of an array Ubound(arrayname)
Assignment
=
Operator
Assigns a value to a variable or property variable = value
Set
Statement
Assigns an object reference to a variable Set variable = object
Comment
Rem
Statement
Declares the following line as a comment to be ignored by the language engine Rem comment_text
Constants/Literals
Empty
Literal
Declares a special uninitialized variable value variable = Empty
False
Constant
A Boolean value representing 0 variable = False
Nothing
Literal
Used to disassociate an object reference from a variable; used in conjunction with Set Set variable = Nothing
Null
Literal
Represents no valid data variable = Null
True
Constant
Boolean value representing -1 variable = True
Conversions
Abs
Function
Returns the unsigned (absolute) value of a number Abs(number)
Asc
Function
Returns the ANSI/ASCII code of a character Asc(string)
CBool
Function
Returns a Boolean subtype Variant value from any valid expression CBool(expression)
CByte
Function
Returns a Byte subtype Variant value from any valid expression Cbyte(expression)
CDate
Function
Returns a Date subtype Variant value from any valid date expression CDate(expression)
CDbl
Function
Returns a Double Precision subtype Variant value from any valid numeric expression CDbl(expression)
Chr
Function
Returns the character corresponding to the ANSI or ASCII code Chr(number)
CInt
Function
Returns an Integer subtype Variant value from any valid numeric expression CInt(expression)
CLng
Function
Returns a Long Integer subtype Variant value from any valid numeric expression CLng(expression)
CSng
Function
Returns a Single Precision subtype Variant value from any valid numeric expression CSng(expression)
CStr
Function
Returns a String subtype Variant value from any valid expression CStr(expression)
DateSerial
Function
Returns a Date subtype Variant from valid year, month, and day values DateSerial(year,month,day)
DateValue
Function
Returns a Date subtype Variant value from any valid date expression DateValue(expression)
Hex
Function
Returns a String subtype Variant representing the hexadecimal value of a number Hex(number)
Int
Function
Returns an Integer subtype Variant rounded down from the number supplied Int(number)
Fix
Function
Returns an Integer subtype Variant rounded up from the number supplied Fix(number)
Oct
Function
Returns a String subtype Variant representing the octal value of a number Hex(number)
Sgn
Function
Returns an Integer subtype Variant representing the sign of a number Sgn(number) values > 0 return 1 values = 0 return 0 values < 0 return -1
TimeSerial
Function
Returns a Date subtype Variant from valid hour, minute, and second values TimeSerial(hour,minute,second)
TimeValue
Function
Returns a Date subtype Variant value from any valid time expression TimeValue(expression)
Dates and Times
Date
Function
Returns the current system date Date()
DateSerial
Function
Returns a Date subtype Variant from valid year, month, and day values. DateSerial(year,month,day)
DateValue
Function
Returns a Date subtype Variant value from any valid date expression. DateValue(expression)
Day
Function
Returns an Integer subtype Variant representing the day (1-31) from a valid date expression Day(dateexpression)
Hour
Function
Returns an Integer subtype Variant representing the hour (0-23) from a valid time expression Hour(timeexpression)
Minute
Function
Returns an Integer subtype Variant representing the minute (0-60) from a valid time expression Minute(timeexpression)
Month
Function
Returns an Integer subtype Variant representing the month (1-12) from a valid date expression Month(dateexpression)
Now
Function
Returns the current date and time of the system Now()
Second
Function
Returns an Integer subtype Variant representing the second (0-60) from a valid time expression Second(timeexpression)
Time
Function
Returns the current system time Time()
TimeSerial
Function
Returns a Date subtype Variant from valid hour, minute and second values TimeSerial(hour,minute,second)
TimeValue
Function
Returns a Date subtype Variant value from any valid time expression TimeValue(expression)
Weekday
Function
Returns an Integer subtype Variant between 1 and 7 representing the day of the week, starting at Sunday, from a date expression Weekday(dateexpression)
Year
Function
Returns an Integer subtype Variant representing the year from a valid date expression Year(dateexpression)
Declarations
Dim
Statement
Declares a variable Dim variable
End
Statement
Declares the end of a Sub procedure or function End Sub End Function
Exit
Statement
Use with Do, For, Function, or Sub to prematurely exit the routine Exit Do/For/Function/Sub
Function
Statement
Declares a function and the argument list passed into the function, and declares the end of a function; also used with Exit to prematurely end a function Function functionname(argumentlist) Exit Function End Function Public variable
Sub
Statement
Declares a custom procedure or event handler and the argument list, if any, and declares the end of a custom procedure or event handler; also used with Exit to prematurely end a custom procedure or event handler Sub subroutinename([argumentlist]) Exit Sub End Sub
Error Handling
Clear
Method
A method of the Err object to reset the Err.Number property to 0 Err.Clear
Description
Property
A property of the Err object that contains a description of the last error as specified in the Err.Number property Err.Description
Err
Object
An object containing information about the last error Err.property|method
On Error
Statement
Used in conjunction with Resume Next to continue execution with the line directly following the line in which the error occurred On Error Resume Next
Raise
Method
A method of the Err object used to simulate the occurrence of an error specified by number Err.Raise(errornumber)
Number
Property
A property of the Err object that contains the error code for the last error, or 0 if no error has occurred Err.Number
Source
Property
Returns the name of the object or application that raised the error Err.Source
Input/Output
InputBox
Function
Displays a dialog box to allow user input InputBox(caption[,title][,value][,x][,y])
MsgBox
Function
Displays a dialog box MsgBox(prompt[, definition][, title])
Operators
+
Operator
Addition of two numerical expressions result = expr1 + expr2
And
Operator
Logical conjunction operator If expression AND expression Then
/
Operator
Division operator result = expression / expression
=
Operator
Equality operator If expression = expression Then
Eqv
Operator
Logical equivalence operator If expression Eqv expression Then
Operator
Exponentiation operator result = expression ^ expression
Operator
Greater than comparison If expression > expression Then
=
Operator
Greater than or equal to comparison If expression >= expression Then
Imp
Operator
Logical implication If expression Imp expression Then
<>
Operator
Inequality comparison If expression <> expression Then
\
Operator
Integer division operator result = expression \ expression
<
Operator
Less than comparison If expression < expression Then
⇐
Operator
Less than or equal to comparison If expression ⇐ expression Then
Mod
Operator
Modulus arithmetic; returns only the remainder of a division of two numbers result = expression mod expression
*
Operator
Multiplication result = expression * expression
-
Operator
Subtraction result = expression - expression
Or
Operator
Logical disjunction If expression Or expression Then
&
Operator
Concatenation of two string values result = string & string
Xor
Operator
Logical exclusion If expression Xor expression Then
Options
Option
Statement
Forces a compile-time error if an Explicit undeclared variable is found Option Explicit
Program Flow
Call
Statement
Passes execution to a subroutine or event handler; also can be used to replicate the actions of the user Call myroutine() Call cmdbutton_OnClick()
Do…Loop
Statement
Repeats code while a condition is met or until a condition is met Do While condition … Loop or Do Until condition … Loop
or Do … Loop While condition or Do … Loop Until condition
For…Next
Statement
Repeats a block of code until the counter reaches a given number For counter = lower to upper [step] … Next
If…Then…Else
Statement
Conditional execution of code If condition Then … (if condition met Else) … (if condition not met) End If
Select Case
Statement
Selective execution of code, where
testexpression must match expression Select Case testexpression Case expression … Case expression … Case Else End Select
While…Wend
Statement
Execution of a code block while a condition is met While expression … Wend
Strings
InStr
Function
Returns the starting point of one string within another string, or 0 if not found result = InStr(start,searched,sought)
Lcase
Function
Converts a string to lowercase result = LCase(string)
Left
Function
Returns the n leftmost characters of a string result = LCase(string)
Len
Function
Returns the length of a string result = Len(string)
Ltrim
Function
Removes all leading spaces result = LTrim(string)
Mid
Function
Returns a string of length L, starting at S within string result = Mid(string, S, L)
Right
Function
Returns the rightmost n characters result = Right(string, n)
RTrim
Function
Removes all trailing spaces from a string result = RTrim(string)
Space
Function
Returns a string consisting of n spaces result = Space(n)
StrComp
Function
Returns an Integer subtype Variant representing the result of a comparison of two strings result = StrComp(string1, string2) string1 < string2 returns -1 string1 < string2 returns 0 string1 < string2 returns 1
String
Function
Returns a string consisting of character C, of length L result = String(L, C)
Trim
Function
Removes both leading and trailing spaces result = Trim(string)
UCase
Function
Returns a string as uppercase alphabetical characters result = UCase(string)
Variants
IsArray
Function
Returns True (-1) if expression is an array, and False (0) if not result = IsArray(expression)
IsDate
Function
Returns True (-1) if expression is a valid date and False (0) if not result = IsDate(expression)
IsEmpty
Function
Returns True (-1) if expression equates to an Empty subtype and False (0) if not result = IsEmpty(expression)
IsNull
Function
Returns True (-1) if expression equates to a Null subtype and False (0) if not result = IsNull(expression)
IsNumeric
Function
Returns True (-1) if expression is a valid numeric expression and False (0) if not result = IsNumeric(expression)
VarType
Function
Returns an integer representing the sub data type of a Variant result = VarType(expression)