Because a program can use different variables, you can declare each variable on its own line. Here are examples: <%@ Page Language="VB" %> <html> <head> <title>Exercise</title> </head> <body> <% Dim NumberOfPages As Integer Dim TownName As String Dim MagazinePrice As Double %> </body> </html> It is important to know that different variables can be declared with the same data type as in the following example: <%@ Page Language="VB" %> <html> <head> <title>Exercise</title> </head> <body> <% Dim NumberOfPages As Integer Dim Category As Integer Dim MagazinePrice As Double %> </body> </html> When two variables use the same data type, instead of declaring each on its own line, you can declare two or more of these variables on the same line. There are two techniques you can use:
You can use the same techniques when declaring many global variables. After declaring the variables, you can initialize and use them as you see fit. We have indicated that when a variable is declared, it receives a default initialization unless you decide to specify its value. Whether such a variable has been initialized or not, at any time, you can change its value by reassigning it a new one. Here is an example: <%@ Page Language="VB" %> <html> <head> <title>Exercise</title> </head> <body> <% ' Initializing a variable when declaring it Dim Number As Double = 155.82 Response.Write("Number: " & Number) ' Changing the value of a variable after using it Number = 46008.39 Response.Write("<br>Number: " & Number) %> </body> </html> An alternative of creating a constant is to specify that a variable is read-only. To do this, use the ReadOnly keyword. While a constant variable can be declared locally, a ReadOnly variable cannot. It must be declared globally. |
|
|||||||||
|