473,790 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Call" function ?


I have a function named

getID3info (lvwDiscInfo.Se lectedItem).

What is the difference between

getID3info (lvwDiscInfo.Se lectedItem)
and
Call getID3info(lvwD iscInfo.Selecte dItem) ?

They both work properly - is there some kind of runtime overhead
difference between the two ?

Thanks.
¤ Alias
Jul 17 '05 #1
3 46968
On Thu, 03 Jul 2003 04:34:37 GMT, ¤ Alias <-@-.> wrote:
[ oops....here is the correct function name]


I have a function named

Public Function getID3info(ByRe f x As String) As Integer

What is the difference between

getID3info (lvwDiscInfo.Se lectedItem)
and
Call getID3info(lvwD iscInfo.Selecte dItem) ?

They both work properly - is there some kind of runtime overhead
difference between the two ?

Thanks.
¤ Alias

Jul 17 '05 #2
> I have a function named

Public Function getID3info(ByRe f x As String) As Integer

What is the difference between

getID3info (lvwDiscInfo.Se lectedItem)
and
Call getID3info(lvwD iscInfo.Selecte dItem) ?

They both work properly - is there some kind of runtime overhead
difference between the two ?


First off, VB has two types of procedures, a Sub and a Function. A Sub
simply executes codes, a Function does the same thing; but, in addition, it
also returns a value. You declared your procedure as a Function, but the two
methods you ask your question about do not show any value being accepted by
the calling routine. Given that, I'd suggest you declare your sample
procedure as a Sub instead. A Function can be used as a Sub, but you are
wasting the memory location that is supposed to hold the return value.

Now, as to your question... whenever you use parentheses around something
that is not part of the syntax, VB evaluates the expression contained inside
(even if there is nothing to "calculate" ). The parentheses in the line with
the Call keyword are part of the syntax, so the (assumed) Sub receives the
arguments ByRef as declared. However, in the other statement, the
parentheses are **not** part of the syntax (see the Remarks section of the
Help files for the Call statement). That means VB evaluates the single
expression it finds enclosed within. It does that by establishing a
temporary memory location in which to carry at the evaluation and passes a
pointer to the evaluated contents at that memory address. This means the Sub
has access to the actual argument being passed by the Call statement and can
modify its value in the calling code's procedure; in the other statement,
the Sub has no access to the argument at all and cannot affect its value
back in the calling procedure. I'd say the reason both expressions work
properly is because you are not changing the value of the argument within
the Sub.

A quick example...

Private Sub Form_Load()
Dim SomeInteger As Integer
SomeInteger = 1
Debug.Print SomeInteger & " <== original value"
AddFive (SomeInteger)
Debug.Print SomeInteger & " <== didn't change"
Call AddFive(SomeInt eger)
Debug.Print SomeInteger & " <== this time, it changed"
AddFive SomeInteger
Debug.Print SomeInteger & " <== no parens, it changed again"
End Sub

Sub AddFive(NumberI n As Integer)
NumberIn = NumberIn + 5
End Sub

Start a new project and paste the above code into the form's code window;
Run the program.

The misuse of parentheses can also generate errors when dealing with
objects. Start a new project and add a TextBox and two(2) CommandButtons and
paste this code into the form's code window

Private Sub Command1_Click( )
Call DeleteText(Text 1)
End Sub

Private Sub Command2_Click( )
DeleteText (Text1)
End Sub

Sub DeleteText(TBox As TextBox)
TBox.Text = ""
End Sub

Run the project, type some text into the TextBox and click Command1. The
text is deleted as expected. Now type some more text into the TextBox and
click Command2. Whoops... an error. Why? Because when you put the
parentheses around that Text1 object, but did not use the Call keyword, you
forced VB to evaluate the Text1 object. TextBoxes have a default property of
Text (the characters making up the content of the TextBox) and it was a
pointer to the temporary memory address VB copied the contents of Text1 to
that was passed. Since this is a String, and not a TextBox object, VB
generated a Type Mismatch error.

Hope the above helped.

Rick - MVP
Jul 17 '05 #3
On Thu, 3 Jul 2003 01:42:16 -0400, "Rick Rothstein"
<ri************ @NOSPAMcomcast. net> wrote:

Rick,
Thanks for the detailed reply. More responses in the copy below.

I have a function named

Public Function getID3info(ByRe f x As String) As Integer

What is the difference between

getID3info (lvwDiscInfo.Se lectedItem)
and
Call getID3info(lvwD iscInfo.Selecte dItem) ?

They both work properly - is there some kind of runtime overhead
difference between the two ?
First off, VB has two types of procedures, a Sub and a Function. A Sub
simply executes codes, a Function does the same thing; but, in addition, it
also returns a value. You declared your procedure as a Function, but the two
methods you ask your question about do not show any value being accepted by
the calling routine. Given that, I'd suggest you declare your sample
procedure as a Sub instead. A Function can be used as a Sub, but you are
wasting the memory location that is supposed to hold the return value.


Yes, you are right. I'm revisiting some code I wrote when I was an
absolute beginner - the function (which reads ID3 info from an MP3)
was probably a cut and paste from some web sample code.

I've changed it to a Sub, since, as you point out, no value is
returned. I've also modified the syntax as advised.
Now, as to your question... whenever you use parentheses around something
that is not part of the syntax, VB evaluates the expression contained inside
(even if there is nothing to "calculate" ). The parentheses in the line with
the Call keyword are part of the syntax, so the (assumed) Sub receives the
arguments ByRef as declared. However, in the other statement, the
parentheses are **not** part of the syntax (see the Remarks section of the
Help files for the Call statement). That means VB evaluates the single
expression it finds enclosed within. It does that by establishing a
temporary memory location in which to carry at the evaluation and passes a
pointer to the evaluated contents at that memory address. This means the Sub
has access to the actual argument being passed by the Call statement and can
modify its value in the calling code's procedure; in the other statement,
the Sub has no access to the argument at all and cannot affect its value
back in the calling procedure. I'd say the reason both expressions work
properly is because you are not changing the value of the argument within
the Sub.
Ok - understood.
A quick example...

Private Sub Form_Load()
Dim SomeInteger As Integer
SomeInteger = 1
Debug.Print SomeInteger & " <== original value"
AddFive (SomeInteger)
Debug.Print SomeInteger & " <== didn't change"
Call AddFive(SomeInt eger)
Debug.Print SomeInteger & " <== this time, it changed"
AddFive SomeInteger
Debug.Print SomeInteger & " <== no parens, it changed again"
End Sub

Sub AddFive(NumberI n As Integer)
NumberIn = NumberIn + 5
End Sub

Start a new project and paste the above code into the form's code window;
Run the program.
I see. Interesting.
The misuse of parentheses can also generate errors when dealing with
objects. Start a new project and add a TextBox and two(2) CommandButtons and
paste this code into the form's code window

Private Sub Command1_Click( )
Call DeleteText(Text 1)
End Sub

Private Sub Command2_Click( )
DeleteText (Text1)
End Sub

Sub DeleteText(TBox As TextBox)
TBox.Text = ""
End Sub

Run the project, type some text into the TextBox and click Command1. The
text is deleted as expected. Now type some more text into the TextBox and
click Command2. Whoops... an error. Why? Because when you put the
parentheses around that Text1 object, but did not use the Call keyword, you
forced VB to evaluate the Text1 object. TextBoxes have a default property of
Text (the characters making up the content of the TextBox) and it was a
pointer to the temporary memory address VB copied the contents of Text1 to
that was passed. Since this is a String, and not a TextBox object, VB
generated a Type Mismatch error.
Got it.
I went ahead and tested option 3:

Private Sub Command2_Click( )
DeleteText Text1
End Sub

and sure enough, it cleared the textbox.
Hope the above helped.
Very much so - I'm glad I asked.
Rick - MVP
Thanks
¤ Alias


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3764
by: Sylwia | last post by:
Hi! I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log files is bigger than a given upper limit, then it starts to delete log files until the space is less than a given
7
5086
by: Vaca Louca | last post by:
Hello, My setup: Debian sarge on dual Pentium 4. g++ 3.3.5-3. (the other system is Windows XP with MS Visual Studio .NET 2003) I have an auto_array<T> template (based on a template taken from the Corona project hosted at SourceForge) which basically wants to implement std::auto_ptr<T> semantics for an array.
2
1618
by: seberino | last post by:
I'm trying run a homegrown profiler on some Python code. Rather than apply profiler wrapper to ALL functions by hand.... Is there a low level Python function I can override to modify how ALL functions are called? Chris
15
2127
by: Steve Jorgensen | last post by:
I'm looking for coding style opinions. It looks to me like most VB/VBA coders use the command-style syntax for calling subs or functions being treated as subs in a particular context ... Foo "ABC", varDest Occasionally, I see code using the Call syntax instead. Call Foo("ABC", varDest)
13
4813
by: Larry Menard | last post by:
Test code: $dbconn = odbc_connect($dbname, $username, $password); $path = "C:\Temp\myJar.jar"; $statement = "CALL SQLJ.INSTALL_JAR('file://$path', 'myJarId')"; $result = odbc_exec($dbconn, $statement); Result: PHP Warning: odbc_exec(): SQL error: CLI0119E Unexpected system failure.
10
2889
by: Thorsten Ottosen | last post by:
Hi, I'm trying to escape html before its saved in a database. I tried $text = htmlentities( $reader->value ); but that don't work for e.g. japanese characters.
5
3350
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
2
2663
by: John M. Gamble | last post by:
I'm getting this message in Visual Studio 2005: PInvokeStackImbalance was detected Message: A call to PInvoke function 'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
2
2890
by: r_ahimsa_m | last post by:
Hello, I am learning PHP5. I need to parse XML file and I found a solution in some book on PHP5 ("PHP5 Programming" by Rasmus Lerdors and others). Unfortunately I have two problems that I don't understand: Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.