|
-
Jun 23rd, 2000, 11:40 AM
#1
Thread Starter
Junior Member
Is there any difference between using a sub or a function when adding a new procedure?
-
Jun 23rd, 2000, 11:59 AM
#2
Hyperactive Member
a function usually returns data and can be used in logic statement like:
Code:
If (IsNumeric(v)) Then
'' blah
End If
where IsNumeric returns a Boolean value
-
Jun 23rd, 2000, 06:16 PM
#3
transcendental analytic
A sub will only process arguments within it
A Function can also return a value so you can handle the function name as a value while a sub must be handled like a statement. Using Call keyword you can also call a function without returning a value
Call Functionname
So Functions are more advanced while Subs are faster.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 23rd, 2000, 10:03 PM
#4
Frenzied Member
Don't worry about the speed difference at all, a Sub is some code to run and a function is a way of working something out
Code:
Public Function CircleArea(Radius As Single) As Double
CircleArea = 3.14159265358979 * Radius * Radius
End Function
Would let you work out the area of a circle eg
Code:
Private Sub Command1_Click
MsgBox "The area of a Circle Radius " & Text1.Text & " is " & CircleArea(Text1.Text) & "."
End Sub
CircleArea is a Function because it returns the area of a circle a Subroutine eqivilent could Be
Code:
Public Sub CircleArea(Radius As Single) As Double
Label1.Caption = (3.14159265358979 * Radius * Radius)
End Sub
Which actually Does something to your code, but is less versitile than the function, Just think what the proceture's for and then decide.
-
Jun 24th, 2000, 10:23 AM
#5
Thread Starter
Junior Member
thanks
thanks a lot for the help people
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
|