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
Thanks

Recommended Answers

All 4 Replies

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

Yes, You can have multiple sub-routines call a function.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.