954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

passing values

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

guins100
Newbie Poster
3 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

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

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

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

guins100
Newbie Poster
3 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

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

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

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

guins100
Newbie Poster
3 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You