|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sub vs Function
Hi,
Can we create functions (not subs) in VB? If so, what is the diff between FUNCTION and SUB? private sub cmd_click private function cmd_click |
|
#2
|
|||
|
|||
|
you can create functions in vb. however, an event is not a function. it is always a sub. the difference between a sub and a function is a function can return a value.
Code:
Private Function Multiply(X As Integer, Y As Integer) As Integer
' inside the function you can use the function
' name as a variable. this is how you return
' a value from a function.
Multiply = X * Y
End Function
' an example call
Dim product As Integer
product = Multiply(5, 4)
__________________
Programmer's Corner |
|
#3
|
|||
|
|||
|
Quote:
LOL, is that the only diff between sub and function? As I vaguely remember, other modern languages like java do not differentiate sub/function/method? |
|
#4
|
|||
|
|||
|
well functions are a little slower. "modern" languages do have a sub/function difference only they do not use a different word for it. you would specify void for a sub that doesn't return a value and any other data type if it does return a value. that isn't an issue of being "modern" as vb.net uses the sub and function keywords. it's all a mater of syntax and BASIC vs C.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Sub vs Function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|