To 'Call' or not to 'Call' (1 Viewer)

Guus2005

AWF VIP
Local time
Today, 11:58
Joined
Jun 26, 2007
Messages
2,645
I see it in a lot of programs. I never use it. Do we need it and why?

What i am talking about is the "Call" keyword.

Code:
Public Sub SomeRoutine()
   ...
End sub

Public Sub Doit()
    Call SomeRoutine
End sub

Public sub WhatIDo()
   SomeRoutine
End Sub

Which is better?

Thanks,

Guus
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:58
Joined
May 7, 2009
Messages
19,169
Call can be used both on Subs/Function.
If you want to ignore the return value of a Func , you use Call.
I always use Call for clarity that you are calling a sub/func than a plain Subname.
 

isladogs

MVP / VIP
Local time
Today, 10:58
Joined
Jan 14, 2017
Messages
18,186
I never use Call either.
Whether 'calling' a function or a button click event, both methods work equally well and I'm not sure either is better.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:58
Joined
Aug 30, 2003
Messages
36,118
I can't take a position on "better", but I never use Call either. I've never heard a reason why it would be better, but perhaps this thread will reveal one.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:58
Joined
Oct 29, 2018
Messages
21,357
Hi. I don't know about being "better" or not either, but I also use Call, like Arnel, to tell myself that I am intentionally ignoring any return value, in that particular case.
 

Mark_

Longboard on the internet
Local time
Today, 03:58
Joined
Sep 12, 2017
Messages
2,111
Not myself, but another programmer I had worked with uses CALL only for code they've added themselves in another module. Simply a "So I remember its not built in" reminder.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:58
Joined
Feb 28, 2001
Messages
26,996
I think I recall a discussion similar to the issues noted by MajP in that linked article. Though it is about VB, a lot of it applies to VBA.

I rarely use CALL myself, but every now and then a reason comes up where CALL is appropriate as a visual reminder to make something stand out. I can think of no techie reasons, but there might be a programming-style reason.
 

Guus2005

AWF VIP
Local time
Today, 11:58
Joined
Jun 26, 2007
Messages
2,645
Even when i call a function of which i dont use the return value i use a dummy variable instead.
Typing a simple Call prefix would be faster.

Thanks for your input everyone!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:58
Joined
Feb 19, 2013
Messages
16,553
Typing a simple Call prefix would be faster.
would think not typing call and not including brackets would be faster

how often do you call msgbox for example?

msgbox "Hello"

v

call msgbox("Hello")
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:58
Joined
Feb 28, 2001
Messages
26,996
Seems to me that NOT using the CALL prefix would be faster because of having fewer characters to type. It wouldn't be much faster to execute. In terms of compiler theory, the only difference between CALL xxxx and direct invocation of xxxx is handled at compile time because by execution time, the work is already done. There should be no difference in the resultant code if the compiler allowed the call in the first place (i.e. no syntax errors). Of course we can't know that since we don't get to see the pseudo-code that gets generated by compilation.

If you used CALL rather than invoke a function in a way to store the result in a throwaway value, there should be one extra instruction compiled from the "throwaway" case - the one that stores the returned value. The CALL case for a function ALSO gets back a value but just doesn't store it. You'd never notice the speed difference unless that was a BIG loop.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:58
Joined
Feb 19, 2002
Messages
42,970
Old habits die hard. Call was required in COBOL so I still use it.

There is an excellent albeit old book out there called "The Psychology of Computer Programming" by Gerald Weinberg. It is about the human aspect of programming rather than the technical aspect. One of the points it makes is that the best languages are rigid and allow one and only one method of doing something. That puts VBA in the poor category since there are various ways to do many things. But I still love Access:)
 

Dreamweaver

Well-known member
Local time
Today, 10:58
Joined
Nov 28, 2005
Messages
2,466
I don't really use it, but sounds a good idear for the function return value I will use it for the same in future thanks


mick
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:58
Joined
Feb 28, 2001
Messages
26,996
Access is OK even though it has automatic type up-conversion within a statement. The one I don't like is old-style C which requires you to run a pre-compiler to catch datatype issues. Classic C allowed you to do abominable things with mixed-mode expressions.

On the other hand, P/L-1 is one of those love to hate/hate to love languages where the typing is SO strict that an 80 character string is NOT the same type as a 79 character string and you have to do explicit typecasts to make them work together. But if you get your code past THAT compiler, you KNOW you don't have any datatype issues. Of course, with typical military logic >>cough, cough, choke<<, the Navy decreed about 15 years ago or so that P/L-1 would be the preferred language for all new software development. Fortunately there were waiver processes for compatibility issues. It was always fun to talk about new programs with the Navy. You never knew quite what would be in the specs, but you just KNEW it wouldn't be easy.
 

Users who are viewing this thread

Top Bottom