Está en la página 1de 6

VBScript Variables

HOME VBScript Variables


VBScript Tutorial Ecommerce
VB HOME Components
VB Introduction for ASP.NET
VB How to WEB HOSTING
VB Where to $15 Domain Name
Examples
VB Variables Registration
VB Procedures Save $20 / year!
Create a variable
VB Conditional
Variables are used to store information. This example UK Domain Names
VB Looping
demonstrates how you can create a variable, and Web Hosting
assign a value to it. Merkaweb Dominios
Examples
VB Examples Buy UK Domain Names
Insert a variable value in a text Register Domain Names
References This example demonstrates how you can insert a
VB Functions variable value in a text. Website Hosting
VB Keywords Domain Hosting
Web Hosting
Create an array
Arrays are used to store a series of related data items. Cheap Domain Names UK
This example demonstrates how you can make an
Domain Names UK
array that stores names. ( We are using a "for loop" to
demonstrate how you write the names. ) Quality Web Hosting
Webmail & POP3 Email
Web Hosting UK
Dedicated Servers UK
What is a Variable? Domain Names UK
Business Web Hosting
A variable is a "container" for information you want to Free Web Hosting
store. A variable's value can change during the script. Cheap Web Hosting
You can refer to a variable by name to see its value or Web Hosting Reseller
to change its value. In VBScript, all variables are of
type variant, that can store different types of data. Website Design UK
Reseller Hosting
HTML & Flash
Download HTML Editor
Rules for Variable Names: Flash Web Builder
Flash Templates
Must begin with a letter HOTELS
Cannot contain a period (.)
Cannot exceed 255 characters

Declaring Variables

http://www.w3schools.com/vbscript/vbscript_variables.asp (1 of 6)4/15/2004 12:25:47 AM


VBScript Variables

You can declare variables with the Dim, Public or the Amsterdam Hotels
Private statement. Like this: Boston Hotels
Chicago Hotels
dim name London Hotels
name=some value Los Angeles Hotels
Miami Hotels
New York Hotels
Now you have created a variable. The name of the New Orleans Hotels
variable is "name". Paris Hotels
Rome Hotels
You can also declare variables by using its name in Hotel Reservations
your script. Like this:
Discount Hotels
Hotel Rooms
name=some value
Web Building
Website Templates
Now you have also created a variable. The name of the Website Builder
variable is "name". Flash Templates
Web Templates
However, the last method is not a good practice, Shopping
because you can misspell the variable name later in Discount Apparel
your script, and that can cause strange results when Online Coupons
your script is running. This is because when you Cooking tools
misspell for example the "name" variable to "nime" the
Men & women clothing
script will automatically create a new variable called
"nime". To prevent your script from doing this you can Office supply
use the Option Explicit statement. When you use this Home Finance
statement you will have to declare all your variables
Shopping UK
with the dim, public or private statement. Put the
Option Explicit statement on the top of your UK Wholesalers
script. Like this:
Mobile Phones
Direct TV
option explicit Plasma TV
dim name Prepaid Phones
name=some value 123 Fast Loans
Software
Meta Search Engine

Assigning Values to Variables Your Own Web Site?

Read W3Schools
You assign a value to a variable like this:
Hosting Tutorial
WebDev Books
name="Hege"
i=200

The variable name is on the left side of the expression


and the value you want to assign to the variable is on
the right. Now the variable "name" has the value
"Hege".

Lifetime of Variables

http://www.w3schools.com/vbscript/vbscript_variables.asp (2 of 6)4/15/2004 12:25:47 AM


VBScript Variables

How long a variable exists is its lifetime. Grow Your


Web Design
When you declare a variable within a procedure, the Business!
variable can only be accessed within that procedure.
When the procedure exits, the variable is destroyed.
These variables are called local variables. You can Download
have local variables with the same name in different a Sample
procedures, because each is recognized only by the
procedure in which it is declared.
Learn CSS
If you declare a variable outside a procedure, all the Positioning the
procedures on your page can access it. The lifetime of easy way!
these variables starts when they are declared, and
ends when the page is closed. Download
a Sample

Learn PHP &


Array Variables MySQL the easy
way!

Sometimes you want to assign more than one value to Download


a single variable. Then you can create a variable that a Sample
can contain a series of values. This is called an array
variable. The declaration of an array variable uses
parentheses ( ) following the variable name. In the SELECTED LINKS
following example, an array containing 3 elements is University Online
declared: Master Degree
Bachelor Degree
dim names(2) Web Security
Web Statistics
The number shown in the parentheses is 2. We start at Web Standards
zero so this array contains 3 elements. This is a fixed-
size array. You assign data to each of the elements of Web Quality
the array like this:

names(0)="Tove"
names(1)="Jani"
names(2)="Stale"

Similarly, the data can be retrieved from any element


using the index of the particular array element you
want. Like this:

mother=names(0)

You can have up to 60 dimensions in an array. Multiple


dimensions are declared by separating the numbers in
the parentheses with commas. Here we have a two-
dimensional array consisting of 5 rows and 7 columns:

dim table(4, 6)

http://www.w3schools.com/vbscript/vbscript_variables.asp (3 of 6)4/15/2004 12:25:47 AM


VBScript Variables

Product Spotlight

Make your big ideas even bigger.


Download your FREE Microsoft ASP.NET Resource Kit
now for hundreds of code samples, step-by-step
program guides, and more. Click here.

Want To Be A Web Master?

If you want to be a Web Master, you will have to host


your web site with an ISP (Internet Service Provider).

Maximum ASP is a service provider with a unique web


hosting platform designed specifically for serious
Microsoft developers. They offer high performance and
stability at a good price with a 30-day, money-back
guarantee.

They have access to all of Microsoft's web


technologies, and their support staff are 100%
Microsoft-certified.

Visit MaximumASP

The Web Design Business Kit

Brendon Sinclair has a unique philosophy that


everyone from Freelancers to the huge International
Web Design Shops can learn from:

http://www.w3schools.com/vbscript/vbscript_variables.asp (4 of 6)4/15/2004 12:25:47 AM


VBScript Variables

Your Web
Design and
Development
skills don't
matter!
You don't have
to be the
cheapest bidder
to win!
Charging by
the hour is the
worst thing you
can do!
Your clients are
everywhere!
When the
project
finishes, your
income should
not!

Want to know more...?

Receive 4 FREE
CHAPTERS in your
inbox:
http://www.sitepoint.
com/launch/3a9053/2/4

or read more:
http://www.sitepoint.
com/launch/3a9053/3/4

We Help You For Free. You Can Help Us!

Make a small donation


Tell your newsgroup or mailing list
Link to us from your pages
Help us correct errors and broken links
Help us with spelling and grammar
Validate the XHTML code of this page

Jump to: Top of Page or HOME or Printer


friendly page

Search W3Schools:

http://www.w3schools.com/vbscript/vbscript_variables.asp (5 of 6)4/15/2004 12:25:47 AM


VBScript Variables

Go!

What Others Say About Us

Does the world know about us? Check out these places:

Google Yahoo Alta Vista MSN Lycos Excite Ask


Jeeves HotBot

W3Schools is for training only. We do not warrant the


correctness of the content. The risk of using it remains
entirely with the user. While using this site, you agree
to have read and accepted our terms of use and
privacy policy.

Copyright 1999-2004 by Refsnes Data. All Rights


Reserved.

How W3Schools
was converted to
XHTML

http://www.w3schools.com/vbscript/vbscript_variables.asp (6 of 6)4/15/2004 12:25:47 AM

También podría gustarte