By Tim Patrick, Steven Roman, Ph.D., Ron Petrusha, Paul Lomax
Book Price: $49.99 USD
£35.50 GBP
PDF Price: $39.99
Cover | Table of Contents
Module Module1
Public Sub Main()
Dim x As Integer
x = 10
MsgBox(Increment(x))
End Sub
Private Function Increment(ByVal baseValue As Integer) As Integer
Return baseValue + 1
End Function
End Module
Module is a variation of a class.Partial keyword. See the entry for that keyword in Chapter 12 for additional information on its usage.
Public Class className
End Class
New keyword. These two steps are often performed in two separate VB
statements.Dim myInstance As SimpleClass ' Defines the variable myInstance = New SimpleClass ' Creates the object
Dim myInstance As SimpleClass = New SimpleClass
Dim myInstance As New SimpleClass
Byte data type can support and manage any 8-bit unsigned integer value, from 0 to 255. It allows no other data values outside of this defined subset, but it handles this subset extremely well. .NET provides data types for those subsets of data that programmers have found essential in software development. These data types make it possible to manipulate virtually any variation of data. For those instances where a predefined .NET data type will not meet your needs, you can use the predefined data types
as building blocks to develop your own custom data management class.Byte data type can support and manage any 8-bit unsigned integer value, from 0 to 255. It allows no other data values outside of this defined subset, but it handles this subset extremely well. .NET provides data types for those subsets of data that programmers have found essential in software development. These data types make it possible to manipulate virtually any variation of data. For those instances where a predefined .NET data type will not meet your needs, you can use the predefined data types
as building blocks to develop your own custom data management class.Integer data type is a wrapper for the System.Int32 structure. One of the members of the Int32 structure is MaxValue, which returns the maximum numeric value allowed for this data type. Thus, even though MaxValue is not officially part of VB, the Integer data type's full dependence on the Int32 data type allows the following usage:
Dim usesInt32 As Integer
MsgBox(usesInt32.MaxValue) ' Displays 2147483647
Dim targetValue As Integer = 5
5 in memory at the address of targetValue." Because it appears on the left side of an assignment operator, the variable (or its memory location) is sometimes called an Const keyword:
accessModifier Const name As type = value
Option Strict is On, all constant declarations must have a declared type.Byte, Integer, Long, or Short, and also—in 2005 or beyond—SByte, UInteger, ULong, or UShort). The enumeration members are shared and read-only for the lifetime of the application.
Public Enum VehicleType As Integer
bicycle = 2
tricycle = 3
passengerCar = 4
eighteenWheeler = 18
End Enum
Dim whatIDrive As VehicleType
whatIDrive = VehicleType.passengerCar
' Implicit constructor: No initial size and no initialization
Dim days( ) As Integer
' Explicit constructor: No initial size and no initialization
Dim days( ) As Integer = New Integer( ) {}
' Implicit constructor: Initial size but no initialization
Dim days(6) As Integer
' Explicit constructor: Initial size but no initialization
Dim days( ) As Integer = New Integer(6) {}
' Implicit constructor: Initial size implied by initialization
Dim days( ) As Integer = {1, 2, 3, 4, 5, 6, 7}
' Explicit constructor, Initial size and initialization
Dim days( ) As Integer = New Integer(6) {1, 2, 3, 4, 5, 6, 7}
Dim myArray(5) As Integer
Dim rectArray(,) As Integer = {{1, 2, 3}, {4, 5, 6}}
Debug.Write(rectArray(0, 0))
Debug.Write(rectArray(0, 1))
Debug.WriteLine(rectArray(0, 2))
Debug.Write(rectArray(1, 0))
Debug.Write(rectArray(1, 1))
Debug.WriteLine(rectArray(1, 2))
' ----- The output is:
123
456
Collection class's members are especially useful.
Dim states As New Collection
states.Add("New York", "NY")
states.Add("Michigan", "MI")
For Each...Next construct.
Dim oneState As String
For Each oneState In states
MsgBox(oneState)
Next oneState