Visual Basic Keywords Included in VB Script | HTML Goodies

Visual Basic Keywords Included in VB Script

Written By
Rick Darnell
Rick Darnell
Jan 13, 2005
6 minute read

VBScript includes all the keywords and features that you need to activate a Web
page. You can’t read or write files, as you’ll learn later in this appendix, but
you can handle any event that an object fires. You can also handle just about any
type of data that you’ll find on a Web page and manipulate the Web page in anyway
you want.


Table C.1 describes each keyword or feature available in VBScript. I’ve divided
this table into broad categories, with each entry under a category describing a single
feature. I’ve used the same categories that Microsoft uses so that you can keep this
information straight as you bounce back and forth between Microsoft’s Web site and
this book. If you don’t find a feature that you expect to see, check out Table C.2
to see if that feature is in the list of Visual Basic features omitted from VBScript.

You can find more information about VBScript’s features at Microsoft’s VBScript
Web site: http://www.microsoft.com/vbscript.

Table C.1  VBScript Keywords



























































































































































































































































































































































































































































































































































































































































Keyword/FeatureDescription
Array handling
IsArrayReturns True if a variable is an array
EraseReinitilizes a fixed-size array
LBound
Returns the lower bound of an array
UBoundReturns the upper bound of an array
Assignments
=Assigns a value to a variable
LetAssigns a value to a variable
SetAssigns an object to a variable
Comments
`Includes inline comments in your script
RemIncludes comments in your script
Constants/Literals
EmptyIndicates an uninitialized variable
NothingDisassociates a variable with an object
NullIndicates a variable with no data
True
Boolean True
FalseBoolean False
Control flow
Do…LoopRepeats a block of statements
For…NextRepeats a block of statements
For Each…NextRepeats a block of statements
If…Then…ElseConditionally executes statements
Select Case
Conditionally executes statements
While…WendRepeats a block of statements
Conversions
AbsReturns absolute value of a number
AscReturns the ASCII code of a character
AscBReturns the ASCII code of a character
AscWReturns the ASCII code of a character
ChrReturns a character from an ASCII code
ChrBReturns a character from an ASCII code
ChrW
Returns a character from an ASCII code
CBoolConverts a variant to a boolean
CByteConverts a variant to a byte
CDateConverts a variant to a date
CDblConverts a variant to a double
CintConverts a variant to an integer
CLngConverts a variant to a long
CSng
Converts a variant to a single
CStrConverts a variant to a string
DateSerialConverts a variant to a date
DateValueConverts a variant to a date
HexConverts a variant to a hex string
OctConverts a variant to an octal string
FixConverts a variant to a fixed string
Int
Converts a variant to an integer string
SgnConverts a variant to a single string
TimeSerialConverts a variant to a time
TimeValueConverts a variant to a time
Dates/Times
DateReturns the current date
TimeReturns the current time
DateSerialReturns a date from its parts
DateValueReturns a date from its value
Day
Returns day from a date
MonthReturns month from a date
WeekdayReturns weekday from a date
YearReturns year from a date
HourReturns hour from a time
MinuteReturns minute from a time
SecondReturns seconds from a time
Now
Returns current date and time
TimeSerialReturns a time from its parts
TimeValueReturns a time from its value
Declarations
DimDeclares a variable
PrivateDeclares script-level private variable
PublicDeclares public-level public variable
ReDimReallocates an array
FunctionDeclares a function
Sub
Declares a subprocedure
Error Handling
On Error
Enables error handling
ErrContains information about last error
Input/Output
InputBoxPrompts the user for input
MsgBoxDisplays a message to the user
Math
AtnReturns the Arctangent of a number
CosReturns the cosine of a number
SinReturns the sine of a number
TanReturns the tangent of a number
ExpReturns the exponent of a number
Log
Returns the logarithm of a number
SqrReturns the square root of a number
RandomizeReseeds the randomizer
RndReturns a random number
Operators
+Addition
Subtraction
^Exponentiation
ModModulus arithmetic
*
Multiplication
/Division

Integer Division
Negation
&String concatenation
=Equality
<>Inequality
<Less Than
<=Less Than or Equal To
>Greater Than
>=Greater Than or Equal To
Is
Compares expressions
AndCompares expressions
OrCompares expressions
XorCompares expressions
EqvCompares expressions
ImpCompares expressions
Objects
CreateObjectCreates reference to an OLE object
IsObjectReturns True if object is valid
Options
Option ExplicitForces explicit variable declaration
Procedures
CallInvokes a subprocedure
FunctionDeclares a function
SubDeclares a subprocedure
Strings
InstrReturns index of a string in another
InStrBReturns index of a string in another
LenReturns the length of a string
LenBReturns the length of a string
Lcase
Converts a string to lowercase
UcaseConverts a string to uppercase
LeftReturns the left portion of a string
LeftBReturns the left portion of a string
MidReturns the mid portion of a string
MidBReturns the mid portion of a string
RightReturns the right portion of a string
RightB
Returns the right portion of a string
SpacePads a string with spaces
StrCompCompares two strings
StringPads a string with a character
LtrimRemoves leading spaces from a string
RtrimRemoves trailing spaces from a string
TrimRemoves leading and trailing spaces
Variants
IsArrayReturns True if variable is an array
IsDateReturns True if variable is a date
IsEmptyReturns True if variable is empty
IsNullReturns True if variable is null.
IsNumericReturns True if variable is a number
IsObjectReturns True if variable is an object
VarTypeIndicates a variable’s type
Advertisement

Visual Basic Keywords Omitted from VBScript


VBScript leaves out a bunch of Visual Basic keywords such as DoEvents,

Print, and Shell. You can’t read or write files, either, and you
can’t do much graphical programming. This won’t stop you from creating great Web
pages with VBScript, though, because VBScript provides every feature you need to
do just about anything you want on the Web page. For example, you can dynamically
change the contents of the Web page itself and you can interact with every object
on the Web page.


Don’t look at the list of omitted keywords and features yet. You need to understand
why Microsoft didn’t include them so that you’ll understand why each feature is on
this list. Take a look:


  • Portability  Microsoft intends to make VBScript available on a variety
    of platforms including Windows, Mac, UNIX, and so on. They’ve wisely removed keywords
    and features that make VBScript less portable to these platforms.


  • Performance  You’ve heard it before: speed or features–pick one. Microsoft
    removed many nonessential features from VBScript so scripts load and run faster.
  • Safety  You should be concerned with security on the Internet. You
    don’t want to open a Web page and discover that it contains a script which crashes
    your drive, do you? Microsoft removed any Visual Basic feature that might cause a
    security problem with scripts such as file I/O. You can still get access to these
    features, however, if you create an ActiveX object which you control with VBScript.

Table C.1 describes each keyword or feature available in Visual Basic but omitted
from VBScript. I’ve divided this table into broad categories, with each entry under
a category describing a single feature. I’ve used Microsoft’s categories so that
you can keep the list on Microsoft’s Web site in sync with this list.





NOTE: The Internet Explorer Script Error dialog box tells you that it found
a statement in your script which couldn’t interpret. I’m sure that you’ve seen error
messages such as "Expected while or until" or nested comments that just
don’t make any sense. When VBScript encounters a keyword it doesn’t recognize, it
spews out all sorts of garbage like the previous example. It usually points to the
offending keyword, however, by placing a caret (^) directly underneath it. The next
time you get one of these unexplained errors, look up the keyword in Table C.2 to
see if Microsoft omitted it from VBScript.

© Copyright Macmillan Computer Publishing. All
rights reserved.

HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.