ASP Net Center.com
VBS Basics
Introduction
Variables & Arrays
Sub & Function Procedure
If Statements
Case Statements
Loop Statements
Operators
Forms

VB Script Sub Procedure

Sub procedure is collection of vb script statements that performs a task and executes when it's called on event procedure. Event procedure is any clickable objects or on load event. Sub procedure does not return a value like function does.
Here is a syntax for sub procedure:
Sub calc()
 your vb script code here
End Sub

The following example is sub procedure that gets users first name and last name then displays users full name on message box. The sub is executed when button is clicked.
<html>
<head>
<script language="vbscript">
sub GetUserName()
 dim firstName
 dim lastName
  firstName=inputbox("Please type your first name")
 lastName=inputbox("Please type your last name")
 msgbox("Your full name is: "&firstName&" "&lastName)
end sub
</script>
</head>
<body>
<form>
 <input type="button" value="Click" onclick="call GetUserName()">
</form>
</body>
</html>
We saw the variables and input box before. Msgbox display message window and writes on anything whithin the brackets. Onclick() is an event executed when the button is clicked and in this case it calls GetUserName sub procedure. When GetUserName is called, all the statements in it is evaluated and executed. Click the following button to view the result
Click the button bellow to view the result from previous example on the variable page.  We put the code in sub procedure similar to the example above.

Variables & Arrays Function Procedures