Visual Basic 2010 Lesson 13- The Built-in Functions

We have introduced the basic concept of functions in the previous lesson. In this lesson, we will examine more built-in functions in VB2010. As a matter of facts, we have introduced three built-in functions in Lesson 8, they are the Len function, the Left function, and the Right Function. In this lesson, you will learn additional built-in functions.

13.1 The Mid Function

The Mid function is used to retrieve a part of the text from a given phrase. The syntax is

Mid(phrase, position,n)

phrase is the string from which a part of the text is to be retrieved.
position is the starting position of the phrase from which the retrieving process begins.
n is the number of characters to retrieve.

* When the user clicks the command button, an input box will pop up asking the user to enter a phrase. After a phrase is entered and OK button is pressed, the label will show the extracted text starting from position 2 of the phrase and the number of characters extracted is 6, as shown in the figures below:

13.2 The Right Function

The Right function extracts the right portion of a phrase. The syntax is

Microsoft.Visualbasic.Right ("Phrase", n)

Where n is the starting position from the right of the phase where the portion of the phrase is going to be extracted. For example:

Microsoft.Visualbasic.Right ("Visual Basic", 4) = asic

Example 13.2

The following code extracts the right portion any phrase entered by the user.

13.9 The Chr and the Asc functions

The Chr function returns the string that corresponds to an ASCII code while the Asc function converts an ASCII character or symbol to the corresponding ASCII code. ASCII stands for “American Standard Code for Information Interchange”. Altogether there are 255 ASCII codes and as many ASCII characters. Some of the characters may not be displayed as they may represent some actions such as the pressing of a key or produce a beep sound. The syntax of the Chr function is