ASP
ASP intro
ASP basics
ASP variables
ASP operators

Programming

Programming intro
Java

Markup

First webpage guide
HTML
XHTML

Style & Layout

CSS

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP

Making money online

Make money online

ASP variables

Variables are a fundamental concept in many computer languages and knowing how to work with them is essential knowledge.

This lesson focuses on:

What is a variable?

A variable is a container which stores information in a computer's memory. Variables store important data that is often times fundamental to a script. For example, you can use a variable to store a users name or the number of times a user visits a certain page on your website. The value of a variable can change all throughout a script.

Declaring variables

In ASP a variable is declared with the Dim keyword. This is the same methodology as with VBScript since VBScript is the default language used in ASP.

Syntax:

Dim variableName

Example:

<%
Dim title
%>

You can declare variables separately or all at once.

Declaring variables separately:

<%
Dim title
Dim numPages
Dim author
Dim genre
%>

Declaring variables all at once:

<%
Dim title, numPages, author, genre
%>

Naming variables

When naming variables, several rules should be followed:

Assigning values to variables

You can assign values to variables using the "=" sign.

Example:

<%
Dim title, numPages

'assign values
title = "A book to read"
numPages = 84
%>

Printing variables

You can print variables using the Response.Write() statement.

Example:

<%
Dim title, numPages, author, genre

'assign values
title = "A book to read"
numPages = 84
author = "Book W. Riter"
genre = "Fiction"

'print the variables
Response.Write("Book title: " & title & "<br />")
Response.Write("Number of pages: " & numPages & "<br />")
Response.Write("Author: " & author & "<br />")
Response.Write("Genre: " & genre & "<br />")
%>

Output:

Book title: A book to read
Number of pages: 84
Author: Book W. Riter
Genre: Fiction

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments