3.6.1 Sub Subprogram

Source: Internet
Author: User

1. Sub subprogram Definition
Syntax:
[Private | Public] Sub subroutine name (parameter table)
Statement Block
[Exit Sub | Return]
Statement Block
End Sub
Where:
* Sub. End Sub indicates the start and End of a subprogram.
A parameter table is a description of the parameters that need to be passed when this subroutine is called. For the parameter format and transmission, see section 3.6.4.
* The subroutine name follows the identifier naming rules.
* Private | Public indicates the subprogram access control type. The default value is Public.
* Exit Sub/Return allows forced Exit of subprograms in the middle.
For example, the following Add subroutine calculates the sum of two parameters a and B and outputs them:
Sub Add (ByVal a As Integer, ByVal B As Integer)
Dim c As Integer
C = a + B
Response. Write ("c =" & c)
En Sub

2. Call Sub subprograms
You can Call Sub subprograms in two formats: Call or Call by subprogram name.
Syntax:
[Call] subroutine [(parameter table)]
The parameter table is a real parameter table. The number and type of parameters must be consistent with the form parameter table. The keyword Call can be omitted. For example, you can use any of the following formats to call the Add Subroutine:
Call Add (10, 20)
Add (10, 20)
Note: When the Sub subprogram does not have parameters, a pair of parentheses after the subprogram name must be omitted.
Example 3.7: rewrite example 3.1 to design the operation that shows the current time as a subroutine Display, and then use the "Call Display" statement to Call it.
Source code is as follows Ex3-7.aspx ):

<% @ Page Language = "vb" %>
<Script Language = "VB" Runat = "Server">
Sub Display
Dim CurrTime
CurrTime = Now
Response. Write ("Current Time: <Br> ")
Response. Write (CurrTime)
End Sub
</Script>
<Html> <Body BgColor = "beige"> <Br>
<Center> <Font Color = "Red" Size = 7 Face = "">
<% Call Display %>
</Font> </Center>
</Body> </Html>

BibliographyPrevious sectionNext section

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.