THE NUMERIC FUNCTIONS

  1.      i.            Conversion Function.
  2.  ii.            Scientific & Mathematical Function.
  3. iii.            Trigonometric Function.

CONVERSION FUNCTION

Visual Basic supplies three functions that convert single-precision and double-precision numbers to integer values. Following table contains the three integer conversion functions.

FUNCTION DESCRIPTION

CInt () Rounds fractional values of .5 and more to the next highest integer.

Fix () Truncates the fractional portion.

Int () Rounds the number down to the integer.

Example:

ans1= Int (14.6)

  ans2= Fix (14.6)

ans3= Int (-14.6)’ Stores-15

ans4= Fix (-14.6)’ Stores-14

The CInt () function returns truly rounded numbers, as shown here:

ans6= CInt (14.6)’ Stores15

ans7= CInt (-14.1)’ Stores-14

Following table contains the rest of the data conversion functions.

FUNCTION DESCRIPTION

CCur () converts the argument to an equivalent currency data type.

CDbI () converts the argument to an equivalent double-precision data type.

CLng () converts the argument to an equivalent long integer data type.

CSng () converts the argument to an equivalent single-precision data type.

CStr () converts the argument to an equivalent string data type.

CVar () converts the argument to an equivalent variant data type.

SCIENTIFIC AND MATHEMATICAL FUNCTION

Following Table lists the scientific and mathematical function that Visual Basic provides.

FUNCTION DESCRIPTION

Abs () Returns the absolute value of the argument.

Cos () Returns the computed cosine of the argument expressed in radians.

Exp () Returns the base of the natural logarithm argument.

Log () Returns the natural logarithm of the argument.

Sin () Returns the computed sine of the argument expressed in radians.

Sqr () Returns the square root of the argument.

Tan () Returns the computed tangent.

Example:

The following expression assigns the sine of 38 degrees to a variable named val:

Val = Sin (38*3.14159/180)

THE STRING FUNCTIONS

The string function allow programmer to strip away characters from string data and change strings in various ways.

The Visual Basic programming language supports both the variable-length and fixed-length strings. String functions also have the following categories.

  1.      i.            Conversion function.
  2.  ii.            Substring and trimming function.
  3. iii.            General string function.

CONVERSION FUNCTIONS

The string case-conversion functions convert the string arguments to uppercase or lowercase character strings. Following Table lists these functions.

FUNCTION DESCRIPTION

LCase () Returns the string argument as a variant data type that’s all lowercase letters.

LCase$ () Returns the string argument as a string data type that’s all lowercase letters.

UCase () Returns the string arguments a variant data type that’s all uppercase letters.

UCase$ () Returns the string arguments as a string data type that’s all uppercase letters.

If the argument already contains one or more characters in the target case, the functions leave those characters alone. The remarks’ following these statements indicates the function return values:

Example:

Title=”Something Good!”

L Let= Lcase$ (Title) ‘some good!

U Let=UCase$ (Title) ‘SOME THING GOOD!

GENERAL STRING FUNCTIONS

Following are some general string functions and their description.

LEN () FUNCTION

The Len () function returns the number of characters stores in string. Often, programmer will have to control sizes to hold long strings. Programmer can use the Lan () function as a guide to calculate how wide a control must be. The following statement stores 14 in the variables named length:

Length= Len (“Blue and Green”)

STR () FUNCTION

Str$ () is used to convert a number to a string. Because Str$ () always converts positive numbers to strings with a leading blank (where the imaginary plus sign appears).

St1=Str$ (234) ‘Stores “234”

St2= LTrim$ (Str$ (234)) ‘Stores “234”

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s