|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can a subroutine return a value
Hi ,
Can a subroutine return a value ? or can it be made to do so ? for eg Private Sub multi() as Integer End Sub this statement gives an error "end of statement" at "as" though. |
|
#2
|
||||
|
||||
|
No it cannot. You need to create a Function to return a value. Subroutines are only used to execute something while Functions can actually execute and return a value.
__________________
Keep it Prodigy, Keep it Real |
|
#3
|
|||
|
|||
|
Quote:
As ProEdge said, as you put the instructions it can't work, the right way is Function multi() as Integer End Function but sub can return a value if the parameter is refered as by reference not as a value, but the syntax is. Sub muti(byref AN_INT as integer) end sub The vaue will be returned in the AN_INT variable |
|
#4
|
||||
|
||||
|
Quote:
Actually, the variable AN_INT isn't returned, when passing ByRef you are actually sending the Procedure the memory address of the object to be affected. The sub does whatever it's going to do, then control is returned back to the code that originally called the Sub. So the object (variable) itself isn't being passed to or from the procedure, only the memory address is getting passed. ByVal - means a copy of the the original object is being used. ByRef - means the original object itself is being used. |
|
#5
|
|||
|
|||
|
Yes. Use ByRef variables as args for your Sub.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Can a subroutine return a value |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|