by Dinesh Thakur Category: Object-oriented programming (OOP)

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

 

 



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.