When we pass a value to a procedure we may pass it ByVal or ByRef.

 

 

ByVal

 

ByRef

The ByVal sends a copy of the argument’s value to the procedure.

The ByRef sends a reference indicating where the value is stored in memory, allowing called procedure to actually change the argument’s original value.

When we want to pass copy of argument we can use ByVal keyword.

When we want to pass the reference to the calling procedure we can use ByRef keyword. The ByRef is Default.

Syntax is :

Private Sub Procedure_name(ByVal var as Integer)

Syntax is :

Private Sub Procedure_name(ByRef var as Integer)

For ex.

Private Sub SelectColor(ByVal lngIncomingColor as Long)

‘ Do Something

End Sub

For ex.

Private Sub SelectColor(ByRef lngIncomingColor as Integer)

‘ Do Something

End Sub

 

 



Dinesh ThakurDinesh Thakur is a Columinist and designer with strong passion and founder of Computer Notes. if you have any ideas or any request please get @me on Google+
linkedin FaceBook Twitter Google Plus