# Syntax of Call Statement VB.NET

Syntax

[Call]procedurename[(argumentlist)]
procedurename

A comma-delimited list of arguments to pass to the subroutine being called

Description
Passes execution control to a procedure, function, or dynamic-link library (DLL) procedure or function

Rules at a Glance

• Use of the Call keyword is optional.
• Regardless of whether the Call keyword is used,argumentlist, if it is present, must be enclosed inparentheses.
• If you use Call to call a function, the function's return value is discarded.

Example

Programming Tips and Gotchas

• To pass a whole array to a procedure, use the array name followed by empty parentheses.
• Some programmers suggest that code is more readable when the Call keyword is used to call subroutines.

VB .NET/VB 6 Differences

In VB 6, parentheses had to be omitted if the Call keyword was omitted andprocedurenamehad more than one argument. In VB .NET, parentheses are required whenever arguments are present.

In VB 6, ifargumentlistconsisted of a single argument, enclosing it in parentheses and omitting the Call statement reversed the method by which the argument was passed to the called function. Thus, an argument ordinarily called by value would be called by reference, and vice versa. In VB .NET, this confusing behavior is not supported.

In VB 6, when calling an external routine defined using the Declare statement, you can override the default method of passing an argument by specifying the ByVal or ByRef keywords before the argument. In VB .NET you cannot change whether an argument is passed by value or by reference in the call to the routine.

CallByName Function

Class
Microsoft.VisualBasic.Interaction

Named Arguments
Yes, if
Args( ) is omitted

Syntax
CallByName(
Object, ProcName, UseCallType, Args( ))

A reference to the object containing the procedure being called.

A constant of the type CallType indicating what type of procedure is being called. CallType constants are listed in the following table.

TABLE

A ParamArray argument representing the arguments required by the procedure being called.

Return Value
Depends on the return value (if any) of the called procedure

Description
Provides a method for calling a class member by name.
Since
ProcNameis a string expression, rather than the literal name of a routine, it is possible to call routines dynamically at runtime using a string variable to hold the various procedure names.

Rules at a Glance

• The return type ofCallByNameis the return type of the called procedure.
• ProcNameis not case sensitive.
• UseCallTypecan either be a numeric value or a constant of the CallType enumeration. In the latter case, the enumeration name must be specified along with the constant name, as in callType.Method.
• Args( ) must be a parameter array. A parameter array is an array used to contain function, procedure, or property arguments that can have a variable number of elements.

Programming Tips and Gotchas

• Since the member to be called is not known at compile time, the performance ofCallByNameis inferior to calling members directly by literal name.
• UsingCallByNamedoes not necessarily require that Option Strict be set Off.

Example
The following example uses a parameter array to call the Multiply method of a class named Math:

VB .NET/VB 6 Differences
In VB 6, you don't have to specify VbCallType as the name of the enumeration to access itsconstants. In VB .NET, you must specify CallType as the name of the enumeration to access itsconstants.

CBool Function

Named Arguments
No

Syntax
CBool(
expression)
expression

Return Value
expressionconverted to Boolean data type (True or False)

Description
Casts
expressionas a Boolean data type

Rules at a Glance

• When a numeric value is converted to Boolean, any nonzero value is converted to True, and zero isconverted to False.
• If the expression to be converted is a string, the string must be capable of being evaluated as a number, or it must be "True" or "False". Any other string generates a runtime error. For example, CBool("one") results in a type mismatch error, whereas CBool("1") is converted to True, and CBool("True") is converted to True

Programming Tips and Gotchas

• You can check the validity of the expression prior to using theCBoolfunction by using theIsNumericfunction.
• Like most of the conversion functions,CBoolis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

CByte Function

Named Arguments
No

Syntax
CByte(
expression)
expression

A string or numeric expression that evaluates to a number between 0 and 255

Return Value
expressionconverted to Byte data type

Description
Converts
expressionto a Byte data type

Rules at a Glance

• If the expression to be converted is a string, the string must be capable of conversion to a numeric expression; this can be checked using theIsNumericfunction.
• Ifexpressionevaluates to less than 0 or more than 255, a runtime error is generated.
• If the value ofexpressionis not a whole number,CByterounds the number prior to conversion.

Example

Programming Tips and Gotchas

• Check that the value you pass toCByteis neither negative nor greater than 255.
• UseIsNumericto ensure that the value passed toCBytecan be converted to a numeric expression.
• When usingCByteto convert floating point numbers, fractional values up to but not including .5 are rounded down, while values above but not including .5 are rounded up. Values whose fractional component is exactly equal to .5 are rounded up if their integral component is odd and down if their integral component is even.
• TheCBytefunction converts an expression to an unsigned byte data type. To convertexpressionto a signed byte data type, create an instance of the SByte class and call its Parse method.
• Like most of the conversion functions,CByteis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

CChar Function

Named Arguments
No

Syntax
CChar(
expression)
Expression

Return Value
A value of type Char

Description
Converts the first character in a string
expressionto a Char data type

Rules at a Glance
CCharextracts the first character of expression and converts it to a Char data type.

Example

Programming Tips and Gotchas

If you wish to convert a numeric code to its corresponding Char data type, use theChrWfunction.

Like most of the conversion functions,CCharis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

CDate Function

Named Arguments

No

Syntax
CDate(
expression)

Return Value
expressionconverted into a Date data type.

Description
Converts
expressionto a Date data type.
The format of
expression—the order of day, month, and year—is determined by the locale setting of the local computer. To be certain a date is recognized correctly byCDate, the month, day, and year elements ofexpressionmust be in the same sequence as the local computer's regional settings; otherwise, theCDatefunction has no idea, for example, that 4 was supposed to be the fourth day of the month, not the month of April.

Rules at a Glance

• You can use any of the date delimiters specified in your computer's regional settings; for most systems, this includes ,, /, -, and .
• The earliest date that can be handled by the Date data type is 01/01/100. The latest date that can be handled by the Date data type is 12/31/9999.
• Programming Tips and Gotchas
• Use theIsDatefunction to determine ifexpressioncan be converted to a date or time.

If you pass an empty string toCDate, an error is generated.

A modicum of intelligence has been built into theCDatefunction. It can determine the day and month from a string, regardless of their position in the string; this applies only where the day number is larger than 12, which automatically distinguishes it from the number of the month. For example, if the string "30/12/97" is passed into theCDatefunction on a system expecting a date format of mm/dd/yy,CDatesees that 30 is too large to represent a month and thus treats it as the day. This can lead to problems because if we accidentally pass a string such as "30/12/97" instead of the intended "3/12/97," then VB does not issue an error message!

If we pass a string whose year specification is less than three characters in length, then VB interprets the year as belonging to the twenty-first century. For instance, the string "1/1/1" is interpreted as "1/1/2001."

If you do not specify a year, theCDatefunction uses the year from the current date on your computer.

Like most conversion functions,CDateis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

CDbl Function

Named Arguments

No

Syntax

CDbl(expression)

-1.79769313486232E308 to -4.94065645841247E-324 for negative values, and 4.94065645841247E-324 to 1.79769313486232E308 for positive values

Return Value
expressioncast as a Double data type.

Description
Converts
expressionto a Double data type

Rules at a Glance

• If the value ofexpressionis outside the range of the double data type, an overflow error is generated.
• expressionmust evaluate to a numeric value; otherwise, a type-mismatch error is generated.

Example

Programming Tips and Gotchas

When converting a string representation of a number to a numeric value, the data type conversion functions, such asCDbl, are preferable to the older function,Val. This is because the data type conversion functions take account of the system's regional settings, whereasValrecognizes only the period as a decimal separator. For example, if a user inputs a value of 6,231,532.11,CDblcorrectly converts it to a double with a value of 6231532.11, whileValreturns a value of 6.

UseIsNumericto test whetherexpressionevaluates to a number.

Like most conversion functions,CDblis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

CDec Function

Named Arguments

No

Syntax

CDec(expression)

The range is +/-79, 228, 162, 514, 264, 337, 593, 543, 950, 335 for numbers with no decimal places. The range is +/-7.9228162514264337593543950335 for numbers with up to 28 decimal places. The smallest possible nonzero number is 0.0000000000000000000000000001.

Return Value
expressioncast as a Decimal type

Description
This function casts
expressionas a Decimal value.

Rules at a Glance

• If the value ofexpressionis outside the range of the Decimal data type, an overflow error is generated.
• expressionmust evaluate to a numeric value; otherwise a type-mismatch error is generated. To prevent this, it can be tested beforehand with theIsNumericfunction.

Example

Programming Tips and Gotchas

The Decimal data type replaces the VB 6 Currency data type and is appropriate for very large, very small, or very high precision numbers.

UseIsNumericto test whetherexpressionevaluates to a number.

When converting a string representation of a number to a numeric, you should use the data type conversion functions—such asCDec—instead ofVal, because the data type conversion functions take account of the system's regional settings. In particular, theCDecfunction recognizes the thousands separator if it is encountered in the string representation of a number. For example, if the user inputs the value 1,827,209.6654,CDecconverts it to a the decimal value 1827209.6654, whileValconverts it to a Double value of 1.

Like most of the conversion functions,CDecis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

Ceiling Function

Class
System.Math

Syntax
Math.Ceiling(
a)

Return Value
A Double containing the smallest integer greater than or equal to the argument
a.

Description
Returns the smallest integer greater than or equal to the argument
a.

Example

Rules at a Glance

• Because this function can only accept numeric values, you may want to check the value you pass using theIsNumericfunction to prevent generating an error.
• This is a Shared member, so it can be used without creating any objects.

VB .NET/VB 6 Differences

The Ceiling function is new to the .NET Framework.

ChDir Procedure

Class
Microsoft.VisualBasic.FileSystem

Syntax

ChDir(path)

The path of the directory to set as the new default directory

Description
Changes the current working (default) directory.

Rules at a Glance

pathcan be an absolute or relative reference.

Changing the default directory does not change the default drive; it only changes a particular drive's default directory.

Example

Programming Tips and Gotchas

The single dot (".") represents the current directory and the double dot ("..") represents the parent of the current directory. If the root directory is the current directory, the statement: ChDir("..")

does not change the current directory and does not produce a syntax error.

Ifpathis not found, or a FileNotFoundExeception exception, 76, "Path not found," is generated. However, ifpathrefers to another machine on the network, error 75, "Path/File access error," is generated.

Although you can use a network path such asNTSERV1d$TestDirto change the current directory on the network admin shareNTSERV1d$, you can't access this drive usingChDrivewithout having the drive mapped to a drive letter, which makes using network paths withChDira little pointless!

UseCurDirto determine the current directory for a particular drive.

VB .NET/VB 6 Differences
In VB .NET,
ChDiris implemented as a procedure (a method of the FileSystem class). In VB 6, it isimplemented as a statement. As a result, the VB .NET version requires parentheses around thepathargument.

Choose Function

Class
Microsoft.VisualBasic.Interaction

Named Arguments
No

Syntax

Choose(index, item_1[,item_2, ...[, item_n]])

An expression that evaluates to the (1-based) index of the object to choose from the list

A comma-delimited list of values from which to choose, or a ParamArray containing values from which to choose

Return Value
The object chosen from the list.

Description
Programmatically selects an object from a predefined list of objects (which are passed as parametersto the function) based on its ordinal position in the list. Using
Chooseis a simpler alternative topopulating an array with fixed values.

Rules at a Glance

The list of items is based from 1, rather than the more usual VB default base of 0.

Because the list consists of objects, you can mix data types within the list; you are not forced to use the same data type for each item in the list. For example,item_1can be a string, whileitem_2can be a long integer, anditem_3can be a floating point number.

If the rounded value ofindexdoes not correspond to an item in the list, the function returns a null string.

Programming Tips and Gotchas

Ifindexis not a whole number, it is rounded before being used.

It is important to note that all items in the list are evaluated. Thus, if we use functions or expressions as parameters, all of the functions are called or all of the expressions are evaluated.

By providingitem_1throughitem_nin the form of a ParamArray, the list of values can be expanded or contracted programmatically at runtime.

You can save memory and create more efficient and self-documenting code by using theChoosefunction instead of creating an array and populating it with fixed values each time the program executes. As the following example illustrates, you can turn several lines of code into one:

VB .NET/VB 6 Differences

In VB 6,item_1throughitem_nmust only take the form of a comma-delimited list. In VB .NET, these arguments can also take the form of an array. This allows the list of choices to be modified dynamically at runtime.

In VB 6,idxmust be greater than .5 and less than .5 plus the number of items in the list, or a runtime error results. In VB .NET, ifidxis out of range, the function returns a null string.

Chr, ChrW Functions

Class
Microsoft.VisualBasic.Strings

Syntax

charcode

An expression that evaluates to a Unicode character code

Return Value
A Char that contains the character represented by
charcode

Description
Returns the character represented by the
charcode

Programming Tips and Gotchas

Use Chr(34) to embed quotation marks inside a string, as shown in the following example:

The following table lists some of the more commonly used character codes that are supplied in the call to theChrfunction:

TABLE

VB .NET/VB 6 Differences

TheChrBfunction is no longer supported.

The VB 6 version of theChrfunction returns a String; the VB .NET version returns a Char.

CInt Function

Named Arguments
No

Syntax

CInt(expression)

The range ofexpressionis -2,147,483,648 to 2,147,483,647; fractions are rounded.

Return Value
expressioncast as an Integer

Description
Converts
expressionto an Integer; any fractional portion ofexpressionis rounded.

Rules at a Glance

expressionmust evaluate to a numeric value; otherwise, a type-mismatch error is generated.

If the value ofexpressionis outside the range of the Integer data type, an overflow error is generated.

When the fractional part ofexpressionis exactly .5,CIntalways rounds it to the nearest even number. For example, .5 rounds to 0, and 1.5 rounds to 2.

Example

Programming Tips and Gotchas

When converting a string representation of a number to a numeric data type, you should use the data type conversion functions—such asCInt—instead ofVal, because the data type conversion functions take into account the system's regional settings. In particular,CIntrecognizes the thousands separator if it's present inexpression, whereasValdoes not. For example, ifexpressionis 1,234, thenCIntsuccessfully converts it to the integer value 1234, whileValconverts it to 1.

UseIsNumericto test whetherexpressionevaluates to a number before performing the conversion.

CIntdiffers from theFixandIntfunctions, which truncate, rather than round, the fractional part of a number. Also,FixandIntalways return the same type of value as was passed in.

CIntconverts an expression to a signed 32-bit integer. To convert an expression to an unsigned 32-bit integer, create an instance of the UInt32 structure, and call its Parse method.

Like most of the conversion functions,CIntis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

VB .NET/VB 6 Differences
The VB .NET
CIntfunction actually corresponds to the VB 6CLngfunction, since both return 32-bit
integers.

Class Statement

Syntax

[accessmodifier] [inheritability] ClassName
statements
End Class

The possible values ofaccessmodifierare Public, Private, and Friend.

One of the keywords, MustInherit or NotInheritable, must be used. MustInherit specifies that objects of this class cannot be created, but that objects of derived classes can be created. NotInheritable specifies that this class cannot be used as a base class.

Description
Defines a class and delimits the statements that define that class' variables, properties, and methods.

Rules at a Glance

ClassNamefollows standard Visual Basic variable-naming conventions.

Within a class code block, members are declared as Public, Private, Protected, Friend, or Protected Friend. The Dim keyword is equivalent to Private when used in class modules (but it is equivalent to Public in structures). Property declarations are automatically Public.

The Class...End Class construct can include the following elements:

Private variable or procedure declarationsThese items are accessible within the class, but do not have scope outside of the class.Public variable or procedure declarationsPublic variables are public properties of the class; Public procedures are public methods of the class.Property declarations

These are the public properties of the class. Default properties can be declared by using the Default keyword.

To define a custom constructor within a class module, define a subroutine calledNew. Note that theNewsubroutine (like any other procedure) can be overloaded.

To define a destructor within a class module, define a function calledDestruct. Destructors cannot be overloaded.

To create an object of a class, use syntax such as:

Dim oObj As CClass

Programming Tips and Gotchas

A property defined as a simple public variable cannot be designated the class' default member.

According to accepted object-oriented programming practices, public properties should be defined using the Property statement, since this allows the value of a property to be modified in a controlled and predictable way. It allows you to validate data and allows your program to know when a property value is being changed. Because this is not possible using simple public variables, defining a public variable that is accessible outside of the class is considered poor programming practice.

The Me or MyClass keywords can be used within the Class...End Class construct to reference the class.

VB .NET/VB 6 Differences
The Class...End Class construct is new to VB .NET. In VB 6, each class was defined in its own class module, which corresponded to a separate CLS file.

Namespace
System.Windows.Forms

Createable
No

Description
The Clipboard object represents the Windows Clipboard, an object that allows data to be shared across processes. The members of the Clipboard class allow data to be placed in and retrieved from the Clipboard.
The Clipboard object can be created as follows:

Dim obj As Clipboard

However, because the Clipboard object's members are shared, you do not need to instantiate the Clipboard object to access its properties and methods. Hence, you can place data on the Clipboard, for instance, with the following code fragment:

Clipboard.SetDataObject(strData)

Application class members marked with a plus sign (+) are discussed in detail in their own entries.

Public Shared Methods
GetDataObject +
SetDataObject +

Clipboard.GetDataObject Method

Class
System.Windows.Forms.Clipboard

Syntax
Clipboard.GetDataObject( )

Return value
An IDataObject object that represents the data currently on the clipboard

Description
Retrieves data from the Clipboard

Rules at a Glance

If the Clipboard contains no data, the GetDataObject method returns Nothing.

Once you have an IDataObject object, you can use the members of the IDataObject class to get information about the Clipboard data, as shown in the following example. The relevant IDataObject members for Clipboard manipulation in VB are GetData, GetDataPresent, and GetFormats.

Example
The following example extracts the text that is currently on the Clipboard:

VB .NET/VB 6 Differences
While the .NET Base Class Library uses the GetDataObject method to retrieve all data from the Clipboard, the Clipboard object in VB 6 included the GetFormat, GetData, and GetText methods toretrieve Clipboard data.

Clipboard.SetDataObject Method

Class
System.Windows.Forms.Clipboard

Syntax
SetDataObject(
data)

Data to place on the Clipboard

Description
Places data on the Clipboard

Example
The following example places text on the clipboard:

Dim s As String = "donna"
clipboard.SetDataObject(s)

VB .NET/VB 6 Differences
While the .NET Base Class Library uses the SetDataObject method to place all data on the Clipboard, the Clipboard object in VB 6 includes two methods, SetData and SetText, depending on the format of the data to be placed on the Clipboard.

CLng Function

Named Arguments
No

Syntax
CLng(
expression)

Ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807; fractions arerounded.

Retur n Value
expressioncast as a Long data type

Description
Converts
expressionto a long integer; any fractional element ofexpressionis rounded.

Rules at a Glance

expressionmust evaluate to a numeric value; otherwise, a type-mismatch error is generated.

If the value ofexpressionis outside the range of the Long data type, an overflow error is generated.

When the fractional part is exactly .5,CLngalways rounds it to the nearest even number. For example, .5 rounds to 0, and 1.5 rounds to 2.

Example

Programming Tips and Gotchas

When converting a string representation of a number to a numeric, you should use the data type conversion functions—such asCLng—instead ofVal, because the data type conversion function takes into account the system's regional settings. In particular,CLngis able to recognize the thousands separator if it's included inexpression, whileValcannot. For example, if a user enters a value of 1,098,234 into a textbox,CLngconverts it to the long integer 1098234, butValconverts it to a value of 1.

UseIsNumericto test whetherexpressionevaluates to a number.

CLngdiffers from theFixandIntfunctions, which truncate, rather than round, the fractional part of a number. Also,FixandIntalways return the same type of value as was passed in.

CLngconverts an expression to a signed long integer. To convert an expression to an unsigned long integer, create an instance of the UInt64 structure and call its Parse method.

Like most of the conversion functions,CLngis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

VB .NET/VB 6 Differences
The VB .NET
CLngfunction returns a 64-bit integer, whereas the VB 6CLngfunction returns a 32-bitinteger

CObj Function

Named Arguments
No

Syntax
CObj(
expression)

Return Value
expressioncast as an Object data type

Description
Converts any expression that can be interpreted as an object to Object

Rules at a Glance
expressioncan be any data type, including a strongly typed object, as the following code fragmentillustrates:

Example
The following code:

casts the string "test" to type Object and places it in the Object variableobj.

Programming Tips and Gotchas

The operation of theCObjfunction is possible because all VB .NET data types are either structures or objects.

Once a data type is converted to type Object, you can display its value by calling its ToString method, as in the following code fragment:

Instead of using theCObjfunction to convert a strongly typed object to a generic Object data type, you can also use simple assignment, as the following code fragment illustrates:

Like most of the conversion functions,CObjis not actually a function in the Microsoft.VisualBasic namespace. Instead, it is similar to a Visual C++ macro; the compiler translates the function call into inline code.

VB .NET/VB 6 Differences
The
CObjfunction is new to VB .NET. The closest equivalent in VB 6 isCVar, which converts a datatype to a Variant.

Collection Class

Namespace
Microsoft.VisualBasic

Createable
Yes

Syntax
Dim
objectvariableAs [New] Collection

The name of the Collection object

Description
A Collection object allows you to store members of any data type, including object data types or even other collection objects, and to retrieve them using a unique key.

Collection objects allow us to create a form of associative array, which is an array whose members are indexed by something more meaningful than an integer. The real power of a collection comes by using collections with class objects. Collection objects are created in exactly the same way as other objects, as in:

In the former syntax, the Collection object is created at the time that theobjvariable is declared, which may be sooner than you actually need the Collection object. The latter syntax gives you more control over the creation process.

Rules at a Glance

You can use a Collection object to store data of any data type, including object types and even other Collection objects.

The Add method of the Collection object is used to add items to the collection (see the Collection.Add entry).

Members of a collection can be accessed using either their ordinal number or their key assuming that one was assigned at the time that the member was added to the collection (see the Collection.Item entry).

The first member in a collection is stored at ordinal position 1 (not at 0, as with arrays).

The Count method returns the number of members in the collection (see the Collection.Count entry).

The Remove method removes items from a collection (see the Collection.Remove entry).

Example
This example shows how you can nest one collection within another collection. We create 10 instances of colSubCollection, each containing two integer values. These colSubCollection objects are stored in the collection named colMainCollection. The code also shows how to read the values of colMainCollection and colSubCollection.

Programming Tips and Gotchas

A highly efficient method of enumerating the members of a collection is to use the For Each...Next loop, as the following example shows

Interestingly, although most Visual Basic data types are merely wrappers for data types in the Base Class Library, the Collection object is a "native" VB data type that's derived from System.Object and implements the ICollection, IEnumerable, and IList interfaces. This can be seen from the following code fragment

Collection.Add Method

Class
Microsoft.VisualBasic.Collection

Syntax
objectvariable.Additem [, key, before, after]

The name of the Collection object to which an item is to be added

An object of any type that specifies the member to add to the collection

A unique string expression that specifies a key string that can be used, instead of a positionalindex, to access a member of the collection

The member to be added placed in the collection after the member identified by theafterargument (more on this in Rules at a Glance)

Description
Adds an object to a collection

Rules at a Glance

If you do not specify abeforeoraftervalue, the member is appended to the end of the collection (in index order).

If you do not specify akeyvalue, you cannot access this member using akey, but instead must access it either by using its ordinal number or by enumerating all the members of the collection with the For Each...Next construct. Thus, keys are highly recommended.

Thebeforeorafterargument can refer to an index or a key. For instance, consider the following code:

Both of the commented lines of code adds the item "bill" between "donna" and "steve." The first line uses the key to specify thebeforeobject, and the second line specifies the ordinal position of thebeforeobject.

Key values must be unique or an error (runtime error 457, "This key is already associated with an element of this collection") is generated.

You can specify abeforeorafterposition, but not both.

Example

Programming Tips and Gotchas

Using named parameters helps to self-document your code:

If yourkeyparameter is a value being brought in from outside your program, you must ensurethat each value is always unique. One method for doing this is illustrated in the entry for theCollection.Item Method.

Collection.Count Property

Class
Microsoft.VisualBasic.Collection

Syntax
objectvariable.Count

Object variable referring to a Collection object

Description
Returns an Integer containing the number of members in the collection.

Rules at a Glance
Collections are 1-based; that is, the index of the first element of a collection is 1. In contrast, arrays are0-based; the index of the first element of an array is 0.

Example

Programming Tips and Gotchas
Because collections are 1-based, you can iterate the members of a collection by using index values ranging from 1 to the value ofobjectvariable.Count.

Collection.Item Method

Class
Microsoft.VisualBasic.Collection

Syntax
objectvariable.Item(index)

An object variable of type Collection

An object variable of type value.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd

VB.NET Topics