|
-
Nov 19th, 2001, 04:53 AM
#1
diff between function and sub?
What is the difference between a function and a sub ?
-
Nov 19th, 2001, 04:56 AM
#2
-= B u g S l a y e r =-
a function returns a value, a sub normally does not.. is that good enough ?
-
Nov 19th, 2001, 04:58 AM
#3
In which circumstance should I use a function and when should I use a sub?
-
Nov 19th, 2001, 04:58 AM
#4
Lively Member
I think a function performs a task, and then always returns a value. Also with a function, it must be passed some arguments. A sub does not have either of these two requirements. A sub can either be called (without being passed any arguments) or triggered on an event (such as a mouse click).
This is by no means a computer science definition, more just an observation of mine.
-
Nov 19th, 2001, 05:00 AM
#5
Conquistador
-
Nov 19th, 2001, 05:01 AM
#6
Conquistador
-
Nov 19th, 2001, 05:13 AM
#7
Hyperactive Member
Originally posted by Darren
Also with a function, it must be passed some arguments.
A function doesn't have to have any arguments passed to it:
VB Code:
Public Function Testing() As Single 'no arguments in the ()
Dim fResult As Single
fResult = Rnd
Testing = fResult
End Function
Private Sub CommandCallFunction_Click()
TextHello = Testing ' no argument
End Sub
-
Nov 19th, 2001, 10:33 AM
#8
Addicted Member
Just to confuse the matter ever more... you are perfectly allowed to create a function and never assign the return value... Now, you can really confuse the heell out of people reading your code.
Is that messed-up or what ?
-
Nov 19th, 2001, 10:37 AM
#9
Originally posted by FrancisC
Just to confuse the matter ever more... you are perfectly allowed to create a function and never assign the return value... Now, you can really confuse the heell out of people reading your code.
Is that messed-up or what ?
A VB function will always return a value.
If you haven't explicitly told what to return a default value will be sent back to the caller.
The default values are zero for numeric data types, and empty string for strings and False for boolean return values.
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|