Summary


In this hour we examined the syntax and semantics for variables and operators in Visual Basic. Variables are defined by three properties: their name, their data type, and their value. The name and data type of a variable are specified when the variable is declared and are immutable. Variables are declared in Visual Basic via the Dim statement in the following fashion:

Dim variableName as type 


The type of a variable dictates what values the variable can contain. Each type has a subset of legal values. For example, a variable of type Integer can store negative or positive whole numbers that range from 2,147,483,648 to 2,147,483,647.

A variable is assigned a value via an assignment statement, which is = in Visual Basic. Along with the assignment operator, there are a number of other operators in Visual Basic, including arithmetic operators, like +, -, *, and /; comparison operators, like <, <=, >, >=, =, and <>; and the string concatenation operator, &.

When you're assigning a value to a variable, it is vital that the type of the value matches the type of the variable. If the types do not match, Visual Basic may be able to implicitly cast the value's type into the needed type.

Casts can be implicit or explicit, narrowing or widening. An explicit cast can be declared by using Visual Basic .NET's built-in CType() function or by using the Convert class's methods. Visual Basic, by default, allows for implicit, narrowing casts. However, when you set the Strict="True" option in the @Page directive of your ASP.NET web page, implicit narrowing casts are not allowed.

In the next hour we will look at control structures in Visual Basic. Control structures allow for changes in the program's instruction execution. Commonly, this is translated into having specified portions of code executed repeatedly until some condition is met, or encapsulating a series of related instructions in a subroutine or function, which can then be invoked in a single line of code.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net