When multiple variables are declared on the (Easy web hosting)

When multiple variables are declared on the same line, if a variable is not declared with a explicit type declaration, then its type is that of the next variable with an explicit type declaration. Thus, in the line: Static x As Long, i, j, k As Integer, s As String the variables i, j, and k have type Integer. (In VB 6, the variables i and j would have type Variant.) When a static variable is initialized on the same line as its declaration, the initialization process is performed only the first time the declaration line is encountered. (Otherwise, the variable would not be static.) VB .NET permits the initialization of variables in the same line as their declaration (at long last!). Thus, we may write: Static x As Integer = 5 to declare an Integer variable and initialize it to 5. Similarly, we can declare and initialize more than one variable on a single line: Static x As Integer = 6, y As Integer = 9 Variables that are not explicitly initialized by the Static statement have the following default values: Data type Initial value All numeric types 0 Boolean False Date 01/01/0001 12:00:00 AM Decimal 0 Object Nothing String Zero-length string (”") Static variables can have procedure-level scope or block-level scope. Static variables with procedure-level scope last the lifetime of the application, but they are accessible only within the procedure in which they are defined. Static variables with block-level scope last the lifetime of the application, but they are accessible only within the code block (such as a looping construct or an If statement) in which they are defined. Programming Tips and Gotchas It is a recognized programming practice when using the Static statement in a procedure to put the Static statement at the beginning of that procedure. Although their value persists between calls to a procedure, Static variables do not have scope outside of the procedure in which they are created. For more on static variables, see Chapter 2. VB .NET/VB 6 Differences When multiple variables are declared on a single line of code in VB 6, variables not explicitly assigned a data type are cast as variants. For example, in the statement: Static Var1, Var2, Var3 As String

Hint: This post is supported by Gama php5 hosting services

Comments are closed.