Whats the diffrence between "CALL sub1" and just "sub1"
Printable View
Whats the diffrence between "CALL sub1" and just "sub1"
the only thing I know of is that with Call, you need to pass parameters like :
Call Sub1("Hello")
as with simply saying "Sub1" its just :
Sub1("Hello")
There is no differnce. Call is an optional keyword that was once used in the old days of Basic.
call can still b useful sometimes tho with things like msgbox coz u dont have to use a variable when u dont need to know what they clicked
if you don't need to know what they click then just don't use Parentheses.
ex:
MsgBox "This Work Just Fine", vbOKOnly
its good for readability...say you've just inheirited a project from some one and you come across this...
The first thing I would think is what the f*** is this supposed to be? Now if it was a small amount of code, I could look through and see a sub or function called makeBacon, but let's say there's 400 lines of code? Do you what to go looking through the entire app for "makeBacon"? I wouldn't... so if you use:Code:makeBacon
you know you're dealing with a procedure of some sort...Code:Call makeBacon
That is a very good point
i didt know u could do msgboxes like that :eek:
!!!!
But anyway, as to the people that say use call for readability, whats wrong with comments?
I tend to use "call" in all of my projects, for sheer readability.
ok, on comments...
do you want to have to do this for every occasion that you call makeBacon? it doesn't seem very practical to me...Code:makeBacon 'this calls the makeBacon subroutine
thanks for the support Lethal :D
Although readability is a very good point and I use it where possible, I don't think you use call to call a function and return a value. So call can only be used when you call a sub or a function where you are not interested in the result. If you want to return a value from the function you cannot use call.
E.g
Call msgbox("Confirm",vbyesno) 'doesn't return a value
msgbox ("confirm",vbyesno) 'returns a value
i see what your saying it wouldn't make sense to do this:
Times like this you make the exceptionCode:Dim X as Integer
x = Call MsgBox "Blah Blah Blah"
By the way, no problem Crypt....:D, great minds think alike..hehe