How to Create a Function in VB?
Una Función es más o menos lo mismo que un Sub (un segmento de código que usted crea), y que puede ser usado siempre que lo desee. La diferencia es que una función devuelve un valor, mientras que un Sub no. Cuan necesitas llamar a la funcion lo haces de la siguiente forma:
Call Funcion(variable1, variable2)
Ó también puede hacerlo como en el siguiente ejemplo:
-
Private Sub Command1_Click()
-
Me.Text3.Text = suma(Me.Text1.Text, Me.Text2.Text)
-
-
End Sub
-
-
Private Function suma(val1, val2)
-
If IsNull(val1) Or IsNull(val2) Then
-
MsgBox "Datos incompletos"
-
Exit Function
-
End If
-
suma = Val(val1) + Val(val2)
-
End Function

