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 |