0% found this document useful (0 votes)
10 views

asp

The document provides an overview of ASP procedures, detailing how to call JavaScript from VBScript and vice versa. It explains the differences between VBScript and JavaScript procedures, including sub and function procedures in VBScript, and how to declare and use variables. Examples illustrate the syntax and functionality of procedures and variables in ASP programming.

Uploaded by

Adnan Aslam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

asp

The document provides an overview of ASP procedures, detailing how to call JavaScript from VBScript and vice versa. It explains the differences between VBScript and JavaScript procedures, including sub and function procedures in VBScript, and how to declare and use variables. Examples illustrate the syntax and functionality of procedures and variables in ASP programming.

Uploaded by

Adnan Aslam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

11/6/24, 7:00 AM ASP VB Procedures

 Tutorials  Exercises  Services   Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R

ASP Procedures
❮ Previous Next ❯

In ASP you can call a JavaScript procedure from a VBScript and vice versa.

Procedures
The ASP source code can contain procedures and functions:

Example
<!DOCTYPE html>
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>

<p>Result: <%call vbproc(3,4)%></p>

</body>
</html>

https://www.w3schools.com/asp/asp_procedures.asp 1/10
11/6/24, 7:00 AM ASP VB Procedures

ShowTutorials
Example »
 Exercises  Services   Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R
Insert the <%@ language="language" %> line above the <html> tag to write the
procedure/function in another scripting language:

Example
<%@ language="javascript" %>
<!DOCTYPE html>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>

<p>Result: <%jsproc(3,4)%></p>

</body>
</html>

Show Example »

ADVERTISEMENT

https://www.w3schools.com/asp/asp_procedures.asp 2/10
11/6/24, 7:00 AM ASP VB Procedures

Ads by
 Tutorials  We'll
Exercises  try
Ad not to show
closed
Services  by that adagain
Stop seeing this ad
Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R
Why this ad?

Differences Between VBScript and JavaScript


When calling a VBScript or a JavaScript procedure from an ASP file written in VBScript,
you can use the "call" keyword followed by the procedure name. If a procedure requires
parameters, the parameter list must be enclosed in parentheses when using the "call"
keyword. If you omit the "call" keyword, the parameter list must not be enclosed in
parentheses. If the procedure has no parameters, the parentheses are optional.

When calling a JavaScript or a VBScript procedure from an ASP file written in JavaScript,
always use parentheses after the procedure name.

VBScript Procedures
VBScript has two kinds procedures:

Sub procedure
Function procedure

VBScript Sub Procedures


A Sub procedure:

is a series of statements, enclosed by the Sub and End Sub statements


can perform actions, but does not return a value
can take arguments

https://www.w3schools.com/asp/asp_procedures.asp 3/10
11/6/24, 7:00 AM ASP VB Procedures

Subsomemysub()
Tutorials 
statements
Exercises  Services   Sign Up Log in

 End
EACT Sub
MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R

or

Sub mysub(argument1,argument2)
some statements
End Sub

Example
Sub mysub()
response.write("I was written by a sub procedure")
End Sub

Show Example »

VBScript Function Procedures


A Function procedure:

is a series of statements, enclosed by the Function and End Function statements


can perform actions and can return a value
can take arguments that are passed to it by a calling procedure
without arguments, must include an empty set of parentheses ()
returns a value by assigning a value to its name

Function myfunction()
some statements
myfunction=some value
End Function

or

https://www.w3schools.com/asp/asp_procedures.asp 4/10
11/6/24, 7:00 AM ASP VB Procedures

Function myfunction(argument1,argument2)
Tutorials 
some statements
Exercises  Services   Sign Up Log in

EACT
 myfunction=some
MYSQL JQUERYvalue
EXCEL XML DJANGO NUMPY PANDAS NODEJS R
End Function

Example
function myfunction()
myfunction=Date()
end function

Show Example »

Calling a Procedure
This simple function procedures is called to calculate the sum of two arguments:

Example
Function myfunction(a,b)
myfunction=a+b
End Function

response.write(myfunction(5,9))

Show Example »

The function "myfunction" will return the sum of argument "a" and argument "b". In this
case 14.

When you call a procedure you can use the Call statement, like this:

https://www.w3schools.com/asp/asp_procedures.asp 5/10
11/6/24, 6:55 AM ASP VB Syntax

 Tutorials  Exercises  Services   Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R

ASP Syntax
❮ Previous Next ❯

All our examples shows the ASP code in red.

This makes it easier for you to understand how ASP works.

ASP Uses VBScript


The default scripting language in ASP is VBScript.

A scripting language is a lightweight programming language.

VBScript is a light version of Microsoft's Visual Basic.

ASP Files
ASP files can be ordinary HTML files. In addition, ASP files can also contain server
scripts.

Scripts surrounded by <% and %> are executed on the server.

The Response.Write() method is used by ASP to write output to HTML.

The following example writes "Hello World" into HTML:

https://www.w3schools.com/asp/asp_syntax.asp 1/8
11/6/24, 6:55 AM ASP VB Syntax

 Tutorials 
Example Exercises  Services   Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R
<!DOCTYPE html>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>

Show Example »

VBScript is case insensitive. Response.Write() can be written as response.write().

Using JavaScript in ASP


To set JavaScript as the scripting language for a web page you must insert a language
specification at the top of the page:

Example

<%@ language="javascript"%>
<!DOCTYPE html>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>

https://www.w3schools.com/asp/asp_syntax.asp 2/8
11/6/24, 6:55 AM ASP VB Syntax

 Tutorials  Exercises  Services 


This tutorial uses the VBScript scripting language.
 Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R

ADVERTISEMENT

More Examples
There is an easy shortcut to Response.Write(). You can use an equal sign (=) instead.

The following example also writes "Hello World" into HTML:

Example
<!DOCTYPE html>
<html>
<body>
<%
="Hello World!"
%>
</body>
</html>

Show Example »

https://www.w3schools.com/asp/asp_syntax.asp 3/8
11/6/24, 6:55 AM ASP VB Syntax

HTML tags can be a part of the output:


 Tutorials  Exercises  Services   Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R
Example

<!DOCTYPE html>
<html>
<body>
<%
Response.Write("<h2>You can use HTML tags to format the text!</h2>")
%>
</body>
</html>

Show Example »

HTML attributes can be a part of the output:

Example

<!DOCTYPE html>
<html>
<body>
<%
Response.Write("<p style='color:#0000ff'>This text is styled.</p>")
%>
</body>
</html>

Show Example »

VBScript Examples
This tutorial contains a lot of VBScript examples.

https://www.w3schools.com/asp/asp_syntax.asp 4/8
11/6/24, 6:56 AM ASP VB Variables

 Tutorials  Exercises  Services   Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R

ASP Variables
❮ Previous Next ❯

Variables are "containers" for storing information.

More Examples
Declare a variable
This example demonstrates how to declare a variable, assign a value to it, and use the
value in a text.

Create an array
Arrays are used to store a series of related data items. This example demonstrates how
to create an array that stores names.

Loop through the HTML headings


How to loop through the six headings in HTML.

Time-based greeting using VBScript


This example will display a different message to the user depending on the time on the
server.

Time-based greeting using JavaScript


This example is the same as the one above, but the syntax is different.

Create and change a variable


How to create a variable, assign a value to it, and then change the value of it.

https://www.w3schools.com/asp/asp_variables.asp 1/10
11/6/24, 6:56 AM ASP VB Variables

Insert a variable value in a text


 Tutorials
How to insert  Exercises
a variable Services 
valuein a text.  Sign Up Log in

EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R

Do You Remember Algebra from School?


Do you remember algebra from school? x=5, y=6, z=x+y

Do you remember that a letter (like x) could be used to hold a value (like 5), and that
you could use the information above to calculate the value of z to be 11?

These letters are called variables, and variables can be used to hold values (x=5) or
expressions (z=x+y).

VBScript Variables
As with algebra, VBScript variables are used to hold values or expressions.

A variable can have a short name, like x, or a more descriptive name, like carname.

Rules for VBScript variable names:

Must begin with a letter


Cannot contain a period (.)
Cannot exceed 255 characters

In VBScript, all variables are of type variant, that can store different types of data.

ADVERTISEMENT

Declaring (Creating) VBScript Variables


Creating variables in VBScript is most often referred to as "declaring" variables.

You can declare VBScript variables with the Dim, Public or the Private statement. Like
this:

Dim x
Dim carname

https://www.w3schools.com/asp/asp_variables.asp 2/10
11/6/24, 6:56 AM ASP VB Variables

Now you have created two variables. The name of the variables are "x" and "carname".
 Tutorials  Exercises  Services   Sign Up Log in
You can also declare variables by using its name in a script. Like this:
EACT
 MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R
carname="Volvo"

Now you have also created a variable. The name of the variable is "carname". However,
this method is not a good practice, because you can misspell the variable name later in
your script, and that can cause strange results when your script is running.

If you misspell for example the "carname" variable to "carnime", the script will
automatically create a new variable called "carnime". To prevent your script from doing
this, you can use the Option Explicit statement. This statement forces you to declare all
your variables with the dim, public or private statement.

Put the Option Explicit statement on the top of your script. Like this:

Option Explicit
Dim carname
carname=some value

Assigning Values to Variables


You assign a value to a variable like this:

carname="Volvo"
x=10

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 "carname" has the value of "Volvo", and
the variable "x" has the value of "10".

VBScript Array Variables


An array variable is used to store multiple values in a single variable.

In the following example, an array containing 3 elements is declared:

https://www.w3schools.com/asp/asp_variables.asp 3/10
11/6/24, 6:56 AM ASP VB Variables

Dim names(2)
Tutorials  Exercises  Services   Sign Up Log in

The MYSQL
EACT number shown
JQUERY in the EXCEL
parentheses
XMLis 2. DJANGO
We start at NUMPY
zero so this array contains
PANDAS 3
NODEJS R
elements. This is a fixed-size array. You assign data to each of the elements of 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)

Assign data to a two-dimensional array:

Example
<html>
<body>

<%
Dim x(2,2)
x(0,0)="Volvo"
x(0,1)="BMW"
x(0,2)="Ford"
x(1,0)="Apple"
x(1,1)="Orange"
x(1,2)="Banana"
x(2,0)="Coke"
x(2,1)="Pepsi"
x(2,2)="Sprite"
for i=0 to 2
https://www.w3schools.com/asp/asp_variables.asp 4/10
11/6/24, 6:56 AM ASP VB Variables

response.write("<p>")
 Tutorials
for j=0 to  2 Exercises  Services   Sign Up Log in
response.write(x(i,j) & "<br />")
EACT
 MYSQL
next JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R
response.write("</p>")
next
%>

</body>
</html>

Show Example »

The Lifetime of Variables


A variable declared outside a procedure can be accessed and changed by any script in
the ASP file.

A variable declared inside a procedure is created and destroyed every time the
procedure is executed. No scripts outside the procedure can access or change the
variable.

To declare variables accessible to more than one ASP file, declare them as session
variables or application variables.

Session Variables
Session variables are used to store information about ONE single user, and are available
to all pages in one application. Typically information stored in session variables are
name, id, and preferences.

Application Variables
Application variables are also available to all pages in one application. Application
variables are used to store information about ALL users in one specific application.

❮ Previous Next ❯

https://www.w3schools.com/asp/asp_variables.asp 5/10

You might also like