Max Function VB.NET

Class
System.Math

Syntax
Math.Max(val1, val2)

val1, val2 Use: Required Data Type: Any

A numeric data type or expression

Return Value
Returns the maximum of val1 and val2, in the widest datatype of the two numbers

Description
Returns the maximum of val1 and val2

Rules at a Glance
If the two arguments do not have the same data type, then the narrower data type is cast to the wider type. For instance, the line:

This is a Shared member, so it can be used without creating any objects.

VB .NET/VB 6 Differences

The Max function is new to the .NET Framework.

Me Operator

Syntax
Me

Description
Represents a reference to the current class from within the class

Rules at a Glance

  • Me is an explicit reference to the current object as defined by the Class...End Class construct.
  • Me corresponds to the C++ this operator.

Example
In this example, a class passes an instance of itself to a function outside the class by using the Me operator.

Programming Tips and Gotchas
  • The Me operator can't be used on the left side of an expression.
  • Me is particularly useful when passing an instance of the current class as a parameter to a routine outside the class.

Mid Function

Class
Microsoft.VisualBasic.Strings

Syntax
Mid(str, start[, length])

str Use: Required Data Type: String

The expression from which to return a substring

Start Use: Required Data Type: Long

The starting position of the substring

length Use: Optional Data Type: Long

The length of the substring

Return Value
String

Description
Returns a substring of a specified length from a given string

Rules at a Glance

  • If str contains Nothing, Mid returns Nothing.
  • If start is greater than the length of str, a zero-length string is returned.
  • If start is less than zero, runtime error 5, "Invalid procedure call or argument," is generated.
  • If length is omitted or length is greater than the length of str, all characters from start to the end of str are returned.

Example
The following example parses the contents of a textbox control (named txtString) and writes each word to a list box (named lstWord). Note the use of the InStr function to determine the position of either a space or a carriage return/line feed character combination—the two characters that can terminate a word in this case:

Programming Tips and Gotchas
  • Use the Len function to determine the total length of str.
  • Use InStr to determine the starting point of a given substring within another string.

Mid Statement

Syntax
Mid(target, start[, length]) = string

target Use: Required Data Type: String

The name of the string variable to be modified

start Use: Required Data Type: Long

The position within stringvar at which the replacement commences

Length Use: Optional Data Type: Long

The number of characters in stringvar to replace

string Use: Required Required: String

The string used to replace characters within stringvar

Description
Replaces a section of a string with characters from another string

Rules at a Glance

  • If you omit length, as many characters of string as can fit into stringvar are used.
  • If start + length is greater then the length of stringvar, string is truncated to fit in the same space as stringvar. This means that the length of stringvar is not altered by the Mid statement.
  • If start is less than 0, runtime error 5, "Invalid procedure call or argument," occurs.

Programming Tips and Gotchas

  • If string is Nothing, a runtime error occurs.
  • VB includes the Replace function, which enhances the functionality of the Mid statement by allowing you to specify the number of times the replacement is carried out in the same string.
  • Because it is a statement, this version of Mid does not accept named arguments.
  • As a statement, Mid is implemented by the compiler, rather than by the Microsoft.VisualBasic.Strings class.

Min Function

Class
System.Math

Syntax
Math.Min(val1, val2)

val1, val2 Use: Required Data Type: Any numeric

A numeric data type or expression

Return Value
Returns the minimum of val1 and val2 in the widest data type of the two numbers

Description
Returns the minimum of val1 and val2, in the same data type as the numbers. See Rules at a Glance for more detail.

Rules at a Glance

  • If the two arguments do not have the same data type, then the narrower data type is cast to the wider type. For instance, the code fragment:
  • displays 454.8 without error. The datatype returned by the function in this instance is a Double.
  • This is a Shared member, so it can be used without creating any objects.

VB .NET/VB 6 Differences
The Min function is new to the .NET Framework.

Minute Function

Class
Microsoft.VisualBasic.DateAndTime

Syntax
Minute(TimeValue)

TimeValue Use: Required Data Type: Date

Date variable or literal date

Return Value
An Integer between 0 and 59, representing the minute of the hour

Description
Extracts the minute component from a given date/time expression

Rules at a Glance

  • If TimeValue is not a valid date/time expression, the function generates runtime error 13, "Type mismatch." To prevent this, use the IsDate function to check the argument before calling the Minute function.
  • If TimeValue contains Nothing, 0 is returned, so be careful here to check for Nothing.
  • You can also use the DatePart function.

MIRR Function

Class
Microsoft.VisualBasic.Financial

Syntax
MIRR(valuearray( ), financerate, reinvestrate)

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

An array of cash flow values

financerate Use: Required Data Type: Double

The interest rate paid as the cost of financing

reinvestrate Use: Required Data Type: Double

The interest rate received on gains from cash investment

Return Value
A Double representing the modified internal rate of return

Description
Calculates the modified internal rate of return, which is the internal rate of return when payments andreceipts are financed at different rates

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). The order of elements within the array should reflect the order in which payments and receipts occur.
  • financerate and reinvestrate are percentages expressed as decimal values. For example, 10% is expressed as 0.10.

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, MIRR will return erroneous results.

MkDir Procedure

Class
Microsoft.VisualBasic.FileSystem

Syntax
MkDir(path)

path Use: Required Data Type: String

The name of the folder to be created

Description
Creates a new folder

Rules at a Glance

  • If you omit the drive from path, a new folder will be created on the current drive.
  • You can specify the drive by using either its local drive letter or its UNC name.
  • path can either be a fully qualified path (i.e., a path from the drive's root directory to the directory to be created) or a relative path (i.e., a path from the current directory).
  • If the directory to be created by the MkDir procedure already exists, an IOException exception is raised.

Programming Tips and Gotchas

  • If your program is running on Windows NT, ensure that the logged-in user has the right to create a folder on the specified drive prior to calling the MkDir procedure.
  • VB does not automatically make the new folder the current folder after a call to MkDir. You will need to call the ChDir procedure to do this.
  • To remove a folder, use the RmDir procedure.
  • Use CurDir to determine the current drive.

Mod Operator

Syntax
result = number1 Mod number2

number1, number2 Use: Required Data Type: Any

A numeric expression

Return Value
Returns the modulus

Description
Returns the modulus, that is, the remainder when number1 is divided by number2. This return value is a non-negative integral data type.

Rules at a Glance

  • Floating point numbers are rounded to integers before the division.
  • If number1 or number2 is Nothing, then an error occurs.
  • The Mod operator returns the data type of number1 and number2 if they are the same type, or the widest data type of number1 and number2 if they are different

Module...End Module Statement

Syntax
accessmodifier Module modulename
' statements
End Module

accessmodifier Use: Optional Type: Keyword

One of the following keywords determine the visibility of the module:

Public
Makes the module visible to all applications

Friend
Makes the module visible throughout the project

modulename Use: Required Type: String literal

The name of the code module

Description
Defines a code block as a code module

Rules at a Glance

  • If accessmodifier is omitted, the module is Public by default.
  • modulename follows standard Visual Basic naming conventions and must be unique within its assembly.
  • statements can consist of the following:
  • Constant and variable definitions
  • Function and procedure definitions

Programming Tips and Gotchas
Internally, code modules are implemented as classes. Their public variables are treated as static fields, and their public functions and procedures are treated as static (shared) methods. This means that, particularly in the event of a naming conflict (where two routines in different code modules have the ame name), you can qualify the function or procedure with the name of the module in which it resides. For example, if the SayHello procedure is found in a module named modLibrary, it can be called as follows:

modLibrary.SayHello( )

If a code module is to contain a routine that serves as a program entry point, that routine must be named Sub Main. It must also have Public scope.
VB .NET/VB 6 Differences
The statement is new to VB .NET. VB 6 placed each code module in a separate BAS file, which rendered beginning and ending statements unnecessary. A single VB .NET file, on the other hand, can contain multiple code modules and classes, thus necessitating the use of beginning and ending statements.

Month Function

Class
Microsoft.VisualBasic.DateAndTime

Syntax
Month(datevalue)

datevalue Use: Required Data Type: Date

Date variable or literal date

Return Value
An Integer between 1 and 12

Description
Returns an integer representing the month of the year of a given date expression

Rules at a Glance
If datevalue contains Nothing, Month returns Nothing

Programming Tips and Gotchas

  • The validity of the date expression, as well as the position of the month element within the date expression, is initially determined by the locale settings of the current Windows system. However, some intelligence has been built into the Month function that surpasses the usual comparison of a date expression to the current locale settings. For example, on a Windows machine set to US date format (mm/dd/yyyy), the date "13/12/1998" would technically be illegal. However, the Month function returns 12 when passed this date. The basic rule for the Month function is that if the system-defined month element is outside legal bounds (i.e., greater than 12), the system-defined day element is assumed to be the month and is returned by the function.
  • Since the IsDate function adheres to the same rules and assumptions as Month, it can be used to determine whether a date is valid before passing it to the Month function.
  • Visual Basic also has a new MonthName function for returning the name of the month.
  • You can also use the DatePart function.

MonthName Function

Class
Microsoft.VisualBasic.DateAndTime

Syntax
MonthName month [, abbreviate]

month Use: Required Data Type: Integer

The ordinal number of the month, from 1 to 12

abbreviate Use: Optional Data Type: Boolean

A flag to indicate if an abbreviated month name should be returned

Return Value
String containing the name of the specified month

Description
Returns the month name of a given month. For example, a month of 1 returns January or (if abbreviate is True) Jan.

Rules at a Glance
The default value for abbreviate is False.

Example

Programming Tips and Gotchas
  • month must be an integer; it cannot be a date. Use DatePart("m", dateval) to obtain a month number from a date.
  • If month has a fractional portion, it is rounded before calling the MonthName function.
  • MonthName with abbreviate set to False is the equivalent of Format(dateval, "mmmm").
  • MonthName with abbreviate set to True is the equivalent of Format(dateval, "mmm").

MsgBox Function

Class
Microsoft.VisualBasic.Interaction

Syntax
MsgBox(prompt[, buttons][, title])

prompt Use: Required Data Type: String

The text of the message to display in the message box dialog box

buttons Use: Optional Data Type: MsgBoxStyle enumeration

The sum of the Button, Icon, Default Button, and Modality constant values

title Use: Optional Data Type: String

The title displayed in the title bar of the message box dialog box

Return Value
A MsgBoxResult enumeration constant indicating the button clicked by the user to close the message box

Description
Displays a dialog box containing a message, buttons, and optional icon to the user. The action taken by the user is returned by the function in the form of an enumerated constant.

Rules at a Glance

  • prompt can contain approximately 1,000 characters, including carriage return characters such as the built-in vbCrLf constant.
  • If the title parameter is omitted, the name of the current application or project is displayed in the title bar.
  • If you omit the buttons argument, the default value is 0; that is, VB opens an application modal dialog box containing only an OK button.
  • The constants of the MsgBoxStyle enumeration can be added together to form a complete buttons argument. The constants can be divided into the following groups:
  • Button Display Constants
    Icon Display Constants
    Default Button Constants
    Modality Constants

  • Only one constant from each group can be used to make up the overall buttons value.

Button Display Constants

TABLE

Button Display Constants

Icon Display Constants

TABLE

Icon Display ConstantsIcon Display Constants

Default Button Constants

TABLE

Default Button Constants

Modality Constants

TABLE

Modality Constants

Return Values
The following intrinsic constants can be used to determine the action taken by the user and representthe value returned by the MsgBox function:

TABLE

Return Values

If the MsgBox contains a Cancel button, the user can press the Esc key and the function's return valuewill be that of the Cancel button.

Programming Tips and Gotchas

  • Application modality means that the user cannot access other parts of the application until a response to the message box has been given. In other words, the appearance of the message box prevents the application from performing other tasks or from interacting with the user other than through the message box.
  • System modality used to mean that all applications were suspended until the message box was closed. However, with multitasking operating systems, such as Windows 95 and Windows NT, this is not the case. Basically, the message box is defined to be a "Topmost" window that is set to "Stay on Top," which means that the user can switch to another application and use it without responding to the message box. But because the message box is the topmost window, it will be positioned on top of all other running applications.
  • Unlike its InputBox counterpart, MsgBox cannot be positioned on the screen. It is always displayed in the center of the screen.
  • If your application is to run out-of-process on a remote machine, you should remove all MsgBox functions since they will not be displayed to the user, but instead will appear on the monitor of the remote server!
  • MsgBox should never be used in ASP.NET applications.

VB .NET/VB 6 Differences
In VB 6, the MsgBox function has five parameters. The last two, helpfile (which specified the path to a help file containing information about the error message) and context (which specified the help context ID within helpfile), are optional. In VB .NET, these two parameters are not supported.

MyBase Keyword

Syntax

MyBase

Description
Provides a reference to the base class from within a derived class. If you want to call a member of the base class from within a derived class, you can use the syntax:

MyBase.MemberName

where MemberName is the name of the member. This will resolve any ambiguity if the derived classalso has a member of the same name.

Rules at a Glance

  • MyBase will call through the chain of inherited classes until it finds a callable implementation.

For example, in the code:

the call to ShowType is eventually resolved as a call to Object.GetType, since all classes areultimately derived from the Object class.
  • MyBase cannot be used to call Private class members.
  • MyBase cannot be used to call base class members marked as MustOverride.

Programming Tips and Gotchas

  • MyBase is commonly used to call back into the overridden member from the member that overrides it in the derived class.
  • The MyBase keyword can be used to call the constructor of the base class to instantiate a member of that class, as in:

MyBase.New(...)

VB .NET/VB 6 Differences
The MyBase keyword is new to VB .NET.

MyClass Keyword

Syntax
MyClass

Description
MyClass is a reference to the class in which the keyword is used.

Rules at a Glance

  • When using MyClass (as opposed to Me) to qualify a method invocation, as in:
  • MyClass.IncSalary( )

    the method is treated as if it was declared using the NotOverridable keyword. Thus, regardless of the type of the object at runtime, the method called is the one declared in the class containing this statement (and not in any derived classes). The upcoming example illustrates this difference between MyClass and Me.

  • MyClass cannot be used with shared members.

Example
The following code defines a class, Class1, and a derived class, Class1Derived, each of which has an
IncSalary method.

Now consider the following code, placed in a form module:
The first call to ShowIncSalary is made using a variable of type Class1 that refers to an object of typeClass1. In this case, both calls:

return the same value, because they both call IncSalary in the base class Class1.However, in the second case, the variable of type Class1 holds a reference to an object of the derivedclass Class1Derived. In this case, Me refers to an object of type Class1Derived, whereas MyClass stillrefers to the base class Class1 wherein the keyword MyClass appears. Thus:

VB .NET/VB 6 Differences
The MyBase keyword is new to VB .NET.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

VB.NET Topics