# Inherits Statement VB.NET

Syntax
Inherits classname

classname Use: required Type: String literal

The name of the inherited (base) class

Description
Specifies the name of the class that is being inherited; that is, the base class

Rules at a Glance

• The Inherits statement must be the first line of code in the class module. It can be preceeded only by blank lines or comments. For example:
• VB.NET supports single inheritance only. That is, there can be only a single Inherits statement in any class module.

Programming Tips and Gotchas

The Inherits statement implements code inheritance. You can also use the Implements statement to implement interface inheritance. In that case, a class can be derived from more than one virtual base class. (In other words, you can effectively implement multiple inheritance through interface inheritance using the Implements statement.

Input Procedure
Class
Microsoft.VisualBasic.FileSystem

Syntax
LineInput(filenumber,value)

filenumber Use: Required Data Type: Integer

Any valid file number

value Use: Required Data Type: Any

Description
Reads delimited data from a file into variables. This statement is used to read files that were created using the Writprocedure, in which case the items are comma delimited with quotation marks around strings.

Rules at a Glance

• Data read by Input has usually been written using the Write procedure.
• Use this statement with files that have been opened in Input or Binary mode only.
• If value is numeric and the Input procedure encounters non-numeric data, an InvalidCastException exception occurs.
• The Input procedure strips off the quotation marks that it finds around strings.
• After the Input procedure reads value, it advances the file pointer to the next unread variable or, if the file contains no additional delimited data, to the end of the file.
• If the end of the file is reached during the operation of the Input procedure, an error is generated.
• The Input procedure assigns string or numeric data to value without modification. However, other types of data can be modified as shown in the following table:

TABLE

• Note that #TRUE# and #FALSE# are case sensitive.

Example

If the file c:data.txt contains the following data: "one", "two", "three" then the following code will print each string on a separate line in the Output window:

Programming Tips and Gotchas

• Use the EOF function to determine whether the end of the file has been reached.
• Use the Write procedure to write data to a file, since Write delimits data fields correctly. This ensures that the data can be read correctly with the Input procedure.

VB .NET/VB 6 Differences
The VB .NET Input procedure corresponds to the VB 6 Input procedure, with a number of significant
differences:

• The # symbol, which optionally preceded filenumber in VB 6, is not supported in VB .NET.
• In VB 6, the value argument could be a comma-delimited list of variables. In VB .NET, it must be a single variable of any type.
• In VB 6, if value is numeric and the data read from the file is not numeric, value is initialized to the default value for that type. In VB .NET, this generates an exception.
• In addition to the standard data types, VB 6 also recognizes Empty, Null, and Error types. In VB .NET, these are not supported.

InputBox Function

Class
Microsoft.VisualBasic.Interaction

Syntax
InputBox(prompt[, title] [, defaultresponse] [, xpos] _
[, ypos])

prompt Use: RequiredDim fr As Integer = FreeFile( ) Data Type: String

The message in the dialog box

title Use: Optional Data Type: String

The title bar of the dialog box

defaultresponse Use: Optional Data Type: String

xpos Use: Optional Data Type: Numeric

The distance in twips from the left-hand side of the screen to the left-hand side of the dialog box

ypos Use: Optional Data Type: Numeric

The distance in twips from the top of the screen to the top of the dialog box

Return Value
A String containing the contents of the text box from the InputBox dialog box.

Description
Displays a dialog box containing a prompt for the user, a text box for entering data, and an OK, a Cancel, and (optionally) a Help button. When the user clicks OK, the function returns the contents of the text box.

Rules at a Glance

• If the user clicks Cancel, a zero-length string ("") is returned. Thus, once again, Microsoft has apparently made it impossible for us to distinguish when the user enters the empty string and when the user hits the Cancel button.
• prompt can contain approximately 1,000 characters, including nonprinting characters like the intrinsic vbCrLf constant.
• If the title argument is omitted, the name of the current application or project is displayed in the title bar.
• If you don't use the default parameter to specify a default entry for the text box, the text box is shown as empty, and a zero-length string is returned when the user does not enter anything in the text box prior to clicking OK.
• xpos and ypos are specified in twips.
• If the xpos parameter is omitted, the dialog box is centered horizontally.
• If the ypos parameter is omitted, the top of the dialog box is positioned approximately onethird of the way down the screen.

Programming Tips and Gotchas

• If you are omitting one or more of the optional arguments and are using subsequent arguments, you must use a comma to signify the missing parameter. For example, the following code fragment will display a prompt, a default string in the text box, and the Help button, but default values will be used for the title and positioning.
• Note that InputBox returns a string. Your code is responsible for converting it to the required data type before using it.

InputString Function

Class
Microsoft.VisualBasic.FileSystem

Syntax
InputString(filenumber, charcount)

filenumber Use: RequiredDim fr As Integer = FreeFile( ) Data Type: Integer

Any valid file number

charcount Use: Required Data Type: Integer

Number of characters to read from file

Return Value
A String containing charcount characters

Description
Reads data from a file into a string variable

Rules at a Glance

• InputString should only be used with files opened in input (OpenMode.Input) or binary mode (OpenMode.Binary).
• InputString begins reading from the current position of the file pointer.
• InputString returns all the characters it reads, regardless of their type. This include spaces, carriage returns, linefeeds, commas, end-of-file markers, unprintable characters, etc.
• Once the function finishes reading charcount characters, it also advances the file pointer charcount characters.

Example

If the file c:data.txt contains the data: abcdefghijklmnopq the following code reads the characters, three at a time:

Programming Tips and Gotchas

• InputString reads data written to a file using the Print, PrintLine, or FilePut functions.
• InputString always attempts to precisely read charcount characters from the file. If there are no charcount characters from the position of the file pointer to the end of the file, InputString attempts to read beyond the end of the file, thereby generating an exception. To prevent this, you should use the LOF function after opening the file to ensure that you don't attempt to read past the end-of-file marker.

VB .NET/VB 6 Differences

• Though a new function in VB .NET, InputString directly corresponds to the Input, Input$, InputB, and InputB$ functions in VB 6.
• The order of parameters are reversed in VB .NET and VB 6. In VB 6, the first parameter is charcount, and the second is filenumber.
• The # symbol, which optionally preceded filenumber in VB 6, is not supported in VB .NET.

InStr Function

Class
Microsoft.VisualBasic.Strings

Syntax

InStr(start, string1, string2[, compare]) or: InStr(string1, string2[, compare]) start Use: Required in first syntax Data Type: Numeric

The starting position for the search

string1 Use: Required Data Type: String

The string being searched

string2 Use: Required Data Type: String

The string being sought

compare Use: Optional Data Type: CompareMethod enumeration

The type of string comparison

Return Value
An Integer indicating the position of the first occurrence of string2 in string1

Description
Finds the starting position of one string within another

Rules at a Glance

• The return value of InStr is influenced by the values of string1 and string2, as the following table details:
• TABLE

• In the second syntax, InStr commences the search with the first character of string1.
• If the start argument is 0 or Nothing, an error occurs.
• The compare argument can be one of CompareMethod.Binary (a case-sensitive comparison) or CompareMethod.Text (a case-insensitive comparison). If comparemode is omitted, the type of comparison is determined by the Option Compare setting.

InStrRev Function

Class
Microsoft.VisualBasic.Strings

Syntax
InstrRev(stringcheck, stringmatch[, start[, compare]])

stringcheck Use: Required Data Type: String

The string to be searched.

stringmatch Use: Required Data Type: String

The substring to be found within stringcheck.

start Use: Optional Data Type: Numeric

The starting position of the search. If no value is specified, start defaults to 1.

compare Use: Optional Type: CompareMethod enumeration

A constant indicating how stringcheck and stringmatch should be compared.

Return Value
Long

Description
Determines the starting position of a substring within a string by searching from the end of the string to
its beginning

Rules at a Glance

• While InStr searches a string from left to right, InStrRev searches a string from right to left.
• The compare argument can be one of CompareMethod.Binary (for a case-sensitive search) or CompareMethod.Text (for a case-insensitive search). If compare is omitted, the type of comparison is binary. Note that Option Compare is not used, unlike with the InStr function.
• start designates the starting point of the search as counted from the start of stringcheck. To start the search at the end of stringcheck, either omit the start argument or set it to -1.
• If stringmatch is found within stringcheck, the value returned by InStrRev is the position of stringcheck from the start of the string.

Example
This example uses both InStr and InStrRev to highlight the different results produced by each. Using astringcheck of "I like the functionality that InStrRev gives", InStr finds the first occurrence of "th" at character 8, while InStrRev finds the first occurrence of "th" at character 26.

Int Function

Class
Microsoft.VisualBasic.Conversion

Syntax
Int(number)

number Use: Required Data Type: Any valid numeric data type

The number to be processed

Return Value
Returns a value of the data type passed to it

Description
Returns the integer portion of a number

Rules at a Glance

• The fractional part of number is removed, and the resulting integer value is returned. Int does not round number to the nearest whole number. For example, Int(100.9) returns 100.
• If number is negative, Int returns the first negative integer less than or equal to number. For example, Int(-10.1) returns -11.

Programming Tips and Gotchas

• Int and Fix work identically with positive numbers. However, for negative numbers, Fix returns the first negative integer greater than number, while Int returns the first negative integer less than number. For example, Fix(-10.1) returns -10, while Int(-10.1) returns -11.
• Don't confuse the Int function with CInt. CInt casts the number passed to it as an Integer data type, whereas Int returns the same data type that was passed to it.

Interface Statement

Syntax

One of the following keywords, which determines the visibility of the interface:

Public Use: Optional Type: Keyword

Indicates that the interface is publicly accessible anywhere both inside and outside of the project

Private Use: Optional Type: Keyword

Indicates that the interface is accessible to any nested types, as well as to the type (if any) in which it is defined

Protected Use: Optional Type: Keyword

Indicates that the interface is accessible only to derived classes; a protected interface can only be declared inside of a class.

Friend Use: Optional Type: Keyword

Indicates that the interface is accessible only within the project that contains the interface definition

Protected Friend Use: Optional Type: Keyword

Indicates that the interface is declard inside of a class and that it is accessible throughout the project that contains the interface definition, as well as to derived classes

Indicates that the interface shadows an identically named element in a base class

name Use: Required Type: String literal

The name of the interface

statements Use: Required Code that defines the interface members that derived classes must implement

Description
Defines a virtual base class along with its public members. The interface can then be implemented byderived classes using the Implements statement.

Rules at a Glance

• The standard naming conventions for name apply. However, by convention, interface names generally begin with the letter I.
• If accessmodifier is omitted, the interface is Public by default.
• The interface definition (statements) may contain the following elements:

Inherits statement
Indicates that name inherits its properties and methods from another interface. Its syntax is:

Inherits interfacename[, interfacename...]

where interfacename is the name(s) of the interface(s) from which name inherits.

Property definitions
Property definitions take the form:

[ Default ] Property proname([arglist]) As type

where procname is the name of the property, Default indicates that procname is a property array (whose argument list is defined by arglist) that is the interface's default property, and type indicates the data type of the property. The ReadOnly and WriteOnly keywords can also be used.

Function definitions
Functions are defined as follows:

Function membername([arglist]) As type

where membername is the name of the function, arglist defines the number and type of arguments that can be passed to the procedure, and type indicates the function's return value..

Procedure definitions
Procedures are defined as follows:

Sub membername[(arglist)]

where membername is the name of the procedure, and arglist specifies the number and type of arguments that can be passed to the procedure.

Event definitions
Events are defined as follows:

Event membername[(arglist)]

where membername is the name of the event, and arglist defines the number and type of arguments that are passed back to an event handler whenever the event is fired.
In each case, the syntax of the statement is different from the "standard" VB .NET syntax. Access modifiers, for instance, are not permitted as a part of interface member definitions, nor are End... statements, such as End Function, End Sub, or End Property.

• The name interface cannot inherit from an interface whose access type is more restrictive than its own. For example, if name is a Public interface, it cannot inherit from a Friend interface.
• Classes that implement the interface must implement each of its methods, which must have the same argument list and, in the case of functions and properties, return a value of the same data type as specified by the interface definition.

Programming Tips and Gotchas
An interface can have only one default property. This includes properties defined in base interfaces, as well as in the interface itself.

VB .NET/VB 6 Differences
The Interface...End Interface construct is new to VB .NET. In VB 6, an interface is defined by creating a class module whose members have no implementation.

IPmt Function

Class
Microsoft.VisualBasic.Financial

Syntax
IPmt(rate, per, nper, pv[, fv[, due]])

rate Use: Required Data Type: Double

The interest rate per period.

per Use: Required Data Type: Double

The period for which a payment is to be computed.

nper Use: Required Data Type: Double

The total number of payment periods.

pv Use: Required Data Type: Double

The present value of a series of future payments.

fv Use: Optional Data Type: Double

The future value or cash balance after the final payment. If omitted, the default value is 0.

due Use: Optional Data Type: DueDate enumeration

A value indicating when payments are due. DueDate.EndOfPeriod (or 0) indicates that payments are due at the end of the payment period; DueDate.BegOfPeriod (or 1) indicates that payments are due at the beginning of the period. If omitted, the default value is DueDate.EndOfPeriod.

Return Value
A Double representing the interest payment

Description
Computes the interest payment for a given period of an annuity based on periodic, fixed payments anda fixed interest rate. An annuity is a series of fixed cash payments made over a period of time. It can be either a loan payment or an investment.

Rules at a Glance

• The value of per can range from 1 to nper.
• If pv and fv represent liabilities, their value is negative; if they represent assets, their value is positive.

Example
The ComputeSchedule function accepts a loan amount, an annual percentage rate, and a number of payment periods. It uses the Pmt function to calculate the payment per period, then returns a two dimensionalarray in which each subarray contains the number of the period, the interest paid for that period, and the principal paid for that period.

Private Function ComputeSchedule(dblAmount As Double, _
dblRate As Double, dblNPer As Double) _
As Object(,)
Dim dblIPmt, dblPmt, dblPrincipal As Double
Dim intPer As Integer
Dim strFmt As String
Dim objArray(,) As Object
ReDim objArray(CInt(dblNPer), 2)
strFmt = "###,###,##0.00"
dblPmt = Pmt(dblRate / 12, dblNPer, -dblAmount, 0, 0)
For intPer = 1 To CInt(dblNPer)
dblIPmt = IPmt(dblRate / 12, intPer, dblNPer, -dblAmount)
dblPrincipal = PPmt(dblRate / 12, intPer, dblNPer, _
-dblAmount)
dblAmount = dblAmount - dblPrincipal
objArray(intPer, 0) = intPer & "."
objArray(intPer, 1) = Format(dblIPmt, strFmt)
objArray(intPer, 2) = Format(dblPrincipal, strFmt)
Next
ComputeSchedule = objArray
End Function

Programming Tips and Gotchas

• rate and nper must be expressed in the same time unit. That is, if nper reflects the number of monthly payments, rate must be the monthly interest rate.
• The interest rate is a percentage expressed as a decimal. For example, if nper is the total number of monthly payments, an annual percentage rate (APR) of 12% is equivalent to a monthly percentage rate of 1%. The value of rate is therefore .01.

IRR Function

Class
Microsoft.VisualBasic.Financial

Syntax
IRR(valuearray( )[, guess])

valuearray( ) Use: Required Data Type: Array of Double

An array of cash flow values

guess Use: Optional Data Type: Double

Estimated value to be returned by the function

Return Value
A Double representing the internal rate of return

Description
Calculates the internal rate of return for a series of periodic cash flows (payments and receipts). The internal rate of return is the interest rate generated by an investment consisting of payments and receipts that occur at regular intervals. It is generally compared to a "hurdle rate," or a minimum return, to determine whether a particular investment should be made.

Rules at a Glance

• valuearray must be a one-dimensional array that contains at least one negative value (a payment) and one positive value (a receipt).
• Individual members of valuearray are interpreted sequentially. That is, valuearray(0) is the first cash flow, valuearray(1) is the second, etc.
• If guess is omitted, the default value of 0.1 is used.
• IRR begins with guess and uses iteration to derive an internal rate of return that is accurate to within 0.00001 percent. If IRR cannot do this within 20 iterations, the function fails.

Programming Tips and Gotchas

• Each element of valuearray represents a payment or a receipt that occurs at a regular time interval. If this is not the case, IRR will return erroneous results.
• If the function fails because it could not calculate an accurate result in 20 iterations, try a different value for guess.

Is Operator

Syntax
object1 Is object2

object1 Use: Required Data Type: Object or any reference type object2 Use: Required Data Type: Object or any reference type

Return Value
Boolean

Description
Compares two object variables or reference variables to determine whether they reference the same object

Rules at a Glance

• Both object1 and object2 must be reference-type variables. This includes string variables, object variables, and array variables, for instance.
• The operation returns a result of True if the references are identical and False if they are not.
• It is also possible to determine whether an object contains a valid reference by replacing object2 with the special Nothing keyword. For example: If oDrive Is Nothing Then
• returns True if oDrive does not refer to an object and False if it does. This is the only method that should be used to test for an uninitialized object reference.

Programming Tips and Gotchas

• You can call the IsReference function to ensure that both object1 and object2 are reference types.
• You may wonder why there is a special Is operator for reference types. When you perform a comparison of scalar variables, you want to know if their values are the same. But in the case of objects, you want to know if two references point to a single object. (Since many objects have identical property values, a test for equal values is meaningless.) Hence, the Is operator is used for this purpose.
• Typically, the Is operator is used in an If...Then...Else construct to take some action if two reference-type variables are the same or if a reference type variable does not point to a valid object.
• The Is operator reports that uninitialized reference types are equal. For instance, the Is operator reports that all of the following are equal:

VB .NET/VB 6 Differences
In VB .NET, strings and arrays are reference types. In VB 6, strings and arrays are not reference types
and, therefore, cannot be used with the Is operator.

IsArray Function

Class
Microsoft.VisualBasic.Information

Syntax
IsArray(varname)

varname Use: Required Data Type: Any variable

A variable that may be an array

Return Value
Boolean (True or False)

Description
Tests whether an object variable points to an array

Rules at a Glance
If the variable passed to IsArray is an array or contains an array, True is returned; otherwise, IsArray returns False.

Example
The following code displays True:

Programming Tips and Gotchas

• Due to the nature of Objects, it is not always obvious if an Object variable contains an array, especially if you have passed the variable to a function and the function may or may not have attached an array to the variable. Calling the array function UBound or trying to access an element in an array that does not exist will generate an error. In these situations, you should first use the IsArray function to determine if you can safely process the array.
• An uninitialized array returns False. For example:

• Array-like data structures, such as the Collection object, return False when passed to the IsArray function.

VB .NET/VB 6 Differences
In VB 6, the IsArray function returns True when passed an uninitialized array. In VB .NET, it returns
False.

IsDate Function

Class
Microsoft.VisualBasic.Information

Syntax
IsDate(expression)

expression Use: Required Data Type: Any

Expression containing a date or time

Return Value
Boolean indicating whether the expression can be converted to a Date

Description
Determines if an expression is of type Date or can be converted to type Date

Rules at a Glance

• Returns True if and only if expression is of type Date or can be converted to type Date.
• Uninitialized date variables also return True.

Programming Tips and Gotchas

• IsDate uses the locale settings of the current Windows system to determine if the value held within the variable is recognizable as a date. Therefore, what is a legal date format on one machine may fail on another.
• IsDate is particularly useful for validating data input. However, don't use IsDate in the VB text box control's Change event. The Change event is fired with every keystroke, which means that when the user starts to enter the date, chances are that the date will be invalid until the point at which the user has completed the data entry.

IsDBNull Function

Class
Microsoft.VisualBasic.Information

Syntax
IsDBNull(expression)

expression Use: Required Data Type: Any expression

Return Value
Boolean

Description
Determines whether expression evaluates to DbNull (that is, is equal to System.DbNull.Value).

Rules at a Glance

• DbNull is not the same as Nothing or an empty string. DbNull is used to denote the fact that a variable contains a missing or nonexistent value, and it is used primarily in the context of database field values.
• Since any expression that contains DbNull evaluates to DbNull, an expression such as:

If var = DbNull Then will always fail. The only way to test for a DbNull value is to use IsDbNull.

VB .NET/VB 6 Differences
The IsDBNull function is new to VB .NET.

IsError Function

Class
Microsoft.VisualBasic.Information

Syntax
IsError(expression)

expression Use: Required Data Type: Object

An object variable that may be an Exception object

Return Value
Boolean (True if expression is an Exception object, False otherwise)

Description
Indicates whether an object is an instance of the Exception class or one of its derived classes

Example

VB .NET/VB 6 Differences
In VB 6, the IsError function takes a variant argument and determines if its subtype is vbError. Most commonly, it is used with the CVErr function to determine if the value returned from a function is an error. In VB .NET, the IsError function is used to test whether an object is an instance of the Exception
class or its derived classes

IsNothing Function

Class
Microsoft.VisualBasic.Information

Syntax
IsNothing(expression)

expression Use: Required Data Type: Any

Return Value
Boolean

Description
Determines whether expression evaluates to Nothing. The line:

If IsNothing(obj) Then is equivalent to: If obj Is Nothing Then

VB .NET/VB 6 Differences
The IsNothing function is new to VB .NET.

IsNumeric Function

Class
Microsoft.VisualBasic.Information

Syntax
IsNumeric(expression)
expression
Use: Required
Data Type: Any expression

Return Value
Boolean

Description
Determines whether expression can be evaluated as a number
Rules at a Glance
If the expression passed to IsNumeric evaluates to a number, True is returned; otherwise, IsNumericreturns False.

Programming Tips and Gotchas
If expression is a date or time, IsNumeric evaluates to False.

IsReference Function

Class
Microsoft.VisualBasic.Information

Syntax
IsReference(expression)

expression Use: Required Data Type: Any

Return Value
Boolean

Description
Returns True if expression contains reference type data, as opposed to value type data.

Rules at a Glance

• IsReference returns False if expression is one of the value data types (Byte, Short, Integer, Long, Single, Double, Boolean, Date, or Char).
• IsReference returns True if expression is a reference data type (String or Object), including an object of a specific type, such as a Collection object.
• IsReference returns True if expression is an array, since an array is a reference type.
• IsReference returns False if expression is a structure, since a structure is a value type.

Example

Programming Tips and Gotchas

Just because a variable has been declared to be of type Object does not mean that the IsReference function will return True when that variable is passed to it as an argument. Consider the following code:

In other words, the IsReference function returns True only if a variable of type Object is Nothing or ifits data subtype is one of the reference types (that is, an instance of a class or a string). If its data subtype is a value type, the function returns False.

VB .NET/VB 6 Differences
The IsReference function is new to VB .NET.