By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,218 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Call: Is it necessary?

lotus18
100+
P: 866
Hello World

Using a Call is it necessary? You can call a function without using that keyword right? Second question, which performs faster, using a Call or not?

Rey Sean
Jan 28 '08 #1
Share this Question
Share on Google+
11 Replies


debasisdas
Expert 5K+
P: 8,127
Specifying CALL is optional and is agood practise to use in programming.

That does not involve any performance issue.
Jan 28 '08 #2

Expert 5K+
P: 8,434
Specifying CALL ... is agood practise to use in programming.
That is entirely a matter of opinion. You would hardly expect to use CALL before every statement, so why pick out particular ones?

Surely the whole point of an extensible language is that the extensions are integrated into it seamlessly, and don't require special coding to use.
Jan 29 '08 #3

P: 20
Using the Call statement is more of a readability preference than anything.

Be aware though, that it's only safe to use it on Subroutines, not Functions, as when it's used on Functions it causes the returned value to be ignored.
Jan 29 '08 #4

Expert 5K+
P: 8,434
Using the Call statement is more of a readability preference than anything.
I'm curious about which way you mean that. I generally find the code much more readable without the Call.
Jan 29 '08 #5

debasisdas
Expert 5K+
P: 8,127
My understanding is CALL should be used to call sub procedures not other event procedures and functions.

It make the code more readable in the sense that while going through the code it can be easily find out . It specifies that anything following that keyword is a sub procedure. It specially comes handy while someone else is going through your code. Specially in maintenance projects.
Jan 29 '08 #6

lotus18
100+
P: 866
It specially comes handy while someone else is going through your code. Specially in maintenance projects.
You have the point. : )

Rey Sean
Jan 29 '08 #7

werks
100+
P: 220
Hello World

Using a Call is it necessary? You can call a function without using that keyword right? Second question, which performs faster, using a Call or not?

Rey Sean
I agree with debasisdas, it is much easier to identify if you use Call


Better Than Yesterday ^^
Jan 29 '08 #8

jamesd0142
100+
P: 469
For what it's worth i agree with killer42, I prefer to read and write code without writing "call".

I believe it's a preference that will differ between programmers.

And here's my reason for posting:

Is it right if you use call to call a function the return value is ignored? I was unaware of this.

Does this not remove the whole point of calling a function?
Jan 29 '08 #9

Expert 5K+
P: 8,434
For what it's worth i agree with killer42, I prefer to read and write code without writing "call".

I believe it's a preference that will differ between programmers.
My point is that with an extensible language such as this, once you create a Sub or Function it effectively becomes part of the language. It's a "black box", presumed to have been tested and working. There should be no need to differentiate by using a special type of call. The name of the routine should be enough to tell you what it does. If there's any question about where the routine comes from, a simple keypress will tell you.

Is it right if you use call to call a function the return value is ignored? I was unaware of this.

Does this not remove the whole point of calling a function?
Well, yes and no. If you need the return value, then sure, it defeats the purpose. But keep in mind that since the function can contain any code you like, it may actually do something. You may want to treat it like a Sub in certain circumstances and not bother with a returned value.

The MsgBox function is a prime example. You can use it to prompt the user and determine what button they clicked. Or you can just show a message and wait for the user to click OK. Do you need to know that they clicked OK?

Examples...
Expand|Select|Wrap|Line Numbers
  1.   Dim UserResponse As Long
  2.  
  3.   ' Before performing some action...
  4.   UserResponse = MsgBox("Are you sure?", vbYesNoCancel, "Confirm Action")
  5.  
  6.   ' After performing some action...
  7.   MsgBox "Finished!"
  8.  
Jan 29 '08 #10

kadghar
Expert 100+
P: 1,295
Hope any of you know why this happens.
Feb 12 '08 #11

Expert 5K+
P: 8,434
Hope any of you know why this happens.
Yes, that was a very simple one. The OP had put unnecessary parentheses around the argument list in the "call". All they needed was to remove them.
Feb 12 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.