3.1 program structure

Source: Internet
Author: User

From example 2.1, we can see that the VB. NET program in the ASP. NET webpage must be placed between tags or between <% and %>. The following is a simple example.

Example 3.1: design the page showing the current time, as shown in 3-1.

 

Figure 3-1 display the current time page

Source code is as follows Ex3-1.aspx ):

1: <% @ Page Language = "VB" %>
2:
3:
4:
5: <%
6: Dim currtime' defines the variable
7: CurrTime = Now get the current time
8: Response. Write ("the current time is:
") 'Output prompt
9: Response. Write (CurrTime) 'output current time
10: %>
11:
12:
13:

Note:
1) the pseudo-commands of line 3, <% @ Page Language = "VB" %>, must be written at the beginning of the Code, indicating that all program code on the Page is written in the VB. NET Language. If you use C #, replace "VB" in the command with "C #".
2) 5th rows ~ Line 10th uses a pair of <% and %> tags to enclose the VB. NET program.
Examples 3.1 and 2.1 provide two types of VB. NET program structures used in ASP. NET web pages. When compiling VB. NET programs, either of these two structures can be selected. Note that the structure of the VB. NET program code enclosed by the <% and %> flag is inherited by ASP. For good structural consideration, we recommend that you use the structure described in Chapter 2nd.
It should be noted that ASP. NET introduces the Codebehind technology, that is, it stores program code in a separate file to separate program code from the page architecture, making the structure clearer. However, Codebehind technology involves concepts such as class and inheritance, which will not be discussed here.
The basic elements that constitute the VB. NET program include: identifiers and keywords, constants, variables, operators and expressions, statements, arrays, procedures, functions and subprograms.
An identifier is a string used to identify constants, variables, types, objects, processes, functions, and subprograms. For example, CurrTime in example 3.1 is used to store the current time. The identifier naming rules are as follows:
? It must start with a letter, followed by letters, numbers, or underscores (_);
? Length: ≤ 255 characters;
? You cannot use the keyword VB. NET.
VB. NET is case insensitive to letters. For example, CurrTime and currtime are the same identifier. Generally, an identifier is composed of one or more words with appropriate meanings, and the first letter of each English word is capitalized, such as Score, Name, and CurrTime.
Keywords are pre-defined by the system and have specific meanings. They are usually used as standard type names and statement keywords. Common keywords are as follows:
And As Boolean Byte ByVal
Call Case Catch Char CInt
Class CLng Const CStr Date
Dim Do Each Else ElseIf
End Exit False Finally
Function Get Handles If Imports
In Inherits Integer Is Long
Loop Me NameSpace New Next
Not Nothing Object On Or
Redim Rem Return Short String
Sub Then To True Try
Until Variant When While
Some comments are often added to the program. Note is a description of the key volume or function used in the program. It is not executed. It is a good programming habit to add annotations to programs to increase program readability.
There are two formats for VB. NET Annotations:
1) Rem comment text. Rem can occupy a whole row or separate the rows with colons after the statement. For example:
Rem constant definition
Or:
Const PI = 3.14159: Rem constant definition
2) 'comment the text. For example:
'Define variables
Or:
Dim currtime' defines Variables
Annotations in single quotes are more flexible and therefore more common.
A program consists of statements. If the statement is short, multiple statements can be placed in one row, and each statement is separated by a colon. For example:
A = 1: B = 2: C = 3
On the contrary, if the statement is long, you can use the "_" to split the statement into multiple rows. For example:
Dim strConnection As String = "data source = (local); initial catalog = SEAL ;"&_
"Integrated Security = FALSE; persist security info = TRUE; packet size = 4096" 'continue


BibliographyPrevious sectionNext section

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.