Methods are procedures associated with objects. Unlike fields and properties, which represent information an object can store, methods represent actions that an object can perform. Methods can affect the values of properties. For example, to use a radio analogy, you can employ a SetVolume method to change the value of a Volume property. Similarly, in Visual Basic .NET, the items of list boxes have a List property, which you can change with the Clear and Add methods.

When you use a method in code, the way you write the statement depends on how many arguments the method requires and whether it returns a value. Generally, you use methods just like you use subroutines or function calls. More specifically, you invoke methods in the same way as module procedures, except that you can qualify methods with an expression specifying the object instance whose method is to be called. When unqualified, the instance is implicitly the Me variable.

To use a method that does not require arguments

In the following example, the Refresh method repaints the picture box:

PictureBox1.Refresh() ' Forces a repaint of the control

Note Some methods, such as Refresh, do not have arguments and do not return values.

To use a method that requires multiple arguments

To use a method that returns a value

This example uses the value returned from the Len method as an argument to MsgBox.

Dim MyStr As String = "Some String"
' Displays "String length is : 11
MsgBox("String length is : " & Len(MyStr))