1. ASP intro
  2. ASP basics
  3. ASP variables
  4. ASP operators

ASP variables

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

This tutorial 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.

Dim variableName
<% 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.

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

Printing variables

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

<% 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 />") %>
Book title: A book to read Number of pages: 84 Author: Book W. Riter Genre: Fiction
© Copyright 2013-2014
Terms of use | Privacy policy | Copyright information