Functions


A function is a predefined procedure which accepts one or more arguments and returns a single value. We (programmers) can write our own functions but many computer applications and languages supply predefined functions.

Functions are similar to methods but methods are associated with an object while functions stand alone.

The Sum() function in spreadsheets is one that most people are familiar with.
 
Predefined functions are used to carry out common operations and make it unnecessary for programmers to “reinvent the wheel”.
 
Functions take the arguments passed (input) to them, do "something" with them (process) and return (output) a value. The arguments passed must be of the correct data type, separated by commas, enclosed in parenthesis, and in the order the function expects to receive them.
 
For example

If we need the uppercase equivalent to a string

strUpper = UCase(“abc”)

Makes strUpper equal to “ABC”

We can pass a function a constant, variable, property, or expression as long as the argument(s) passed to the function is the correct data type, that is, it is the data type the function is expecting.

 

strName = UCase(txtName.Text)