I am having difficulty understanding the process of passing values in vb..
If you name a sub procedure (Subsum) in one event procedure can you call it in another using the sam ecaal statement? and do you have to use the same
parameter(byval-byref)? I am quite new to programming

11 Years
Discussion Span
Last Post by guins100

Umm ecaal statement???

OK, see if this helps.

Dim nValue1 as Integer
Dim nValue2 as Integer
Dim nResult as Integer

nValue1 = 5
nValue2 = 10
nResult = AddValues(nValue1, nValue2)

Function AddValues(Paramater1 as Integer, Parameter2 as Integer) as Integer
AddValues = Parameter1 + Parameter2
Return AddValues
End Function

Msgbox "The Result is: " nResult

The values are passed to the procedure by Calling the AddValues Function, which accepts to arguements (or parameters).

1. ByVal is used when you don't want the procedure (function) to modify the variable that is passed to the procedure through an arguement.

2. ByRef is ued when you want to allow the procedure to modify the variable that is passed to the procedure.

Hope this helps


Sorry about the mis-spelling.Yes it does help, I am curious though, can I have an event procedure(btnDisplay_click) call Function AddValues, and then have another event procedure(btnTotal_click) call the Function AddValues?Or do I need to make it a Sub procedure? Thank You for your help. I do seem to be having a brain-fart with this one


Thanks to those that answered my questions.
It has helped tremendously.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.