Directives

Denoting a Variable's Data Type

Table 3-1 lists the prefixes you can use to denote a variable's data type.

If you're unsure of what prefix to use, use obj. For instance, when automating Microsoft Word, you might create an instance of Word's Application object. Because no prefix has been designated specifically for Word objects, obj works just fine, as shown in the following statement:

Dim objWord As Word.Application 

 

Table 3-1. Prefixes for Variable Data Types 

Data Type

Prefix

Example

Boolean

bln

blnLoggedIn

Byte

byt

bytAge

Char

chr

chrInitial

Decimal

dec

decInterestRate

Double

dbl

dblMiles

Integer

int

intAge

Long

lng

lngOnHand

Object

obj

objUserTable

Short

srt

srtTotalIterations

Single

sng

sngYears

String

str

strName

Array

a

Used with another prefix, as in astrEmployees

 

What used to be called user-defined data types (UDTs) in previous versions of Visual Basic are now known as structures. Structures extend the user-defined types of earlier versions, offering you additional functionality such as the support for methods. The ability to create classes has rendered structures unnecessary in many cases, but you'll probably still have occasion to use a structure. Structures are composed of multiple variables, often of different types. When defined, the structure should be prefixed with stc if it isn't public. Public structures should have no prefixes (just as you shouldn't prefix public classes). Regardless, you'll probably want to avoid using a prefix on the structure's variables, because they act much like members of an object. For example:

Private Structure stcPrinter    Private DriverName As String    Private DeviceName As String    Private Port As String    Private Copies As Integer    Private Orientation As Long End Structure 

When creating a variable to hold a structure, use stc, as in:

Dim stcCurrentPrinter As New stcPrinter() 

Unfortunately, stc doesn't tell you anything about the specific structure that the variable holds, but because the possibilities are endless and vary from program to program, it's impossible to assign structure variables specific prefixes.

Note that prefixing an array variable is different from prefixing other types of variables. You use a to denote that the variable is an array, but you then follow the a with the prefix for the array's data type. For example:

Dim asngGrades(9) As Single 


Practical Standards for Microsoft Visual Basic. NET
Practical Standards for Microsoft Visual Basic .NET (Pro-Developer)
ISBN: 0735613567
EAN: 2147483647
Year: 2005
Pages: 84

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