Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Call keyword do in VB6?

Tags:

syntax

vba

vb6

There's some code in our project that looks a bit like this:

Private Sub Method1()     Call InnerMethod End Sub  Private Sub Method2()     InnerMethod End Sub  Private Sub InnerMethod()     '' stuff End Sub 

What's the advantage of doing Method1 over Method2?

like image 915
Ant Avatar asked Jan 26 '09 14:01

Ant


People also ask

What does the call statement do in VBA?

Transfers control to a Sub procedure, Function procedure, or dynamic-link library (DLL) procedure.

What is a call statement?

The CALL statement transfers control from one object program to another within the run unit. The program containing the CALL statement is the calling program; the program identified in the CALL statement is the called subprogram.

How do you call a Function in vb6 0?

You call a Function procedure by using the procedure name, followed by the argument list in parentheses, in an expression. You can omit the parentheses only if you aren't supplying any arguments. However, your code is more readable if you always include the parentheses.

How do you call a procedure in Visual Basic?

To call a Function procedure in an assignment statementUse the Function procedure name following the equal ( = ) sign in the assignment statement. Follow the procedure name with parentheses to enclose the argument list. If there are no arguments, you can optionally omit the parentheses.


1 Answers

From the MSDN:

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.

For example:

Sub Proc1()     Debug.Print "Hello World" End Sub  Sub Proc2(text As String)     Debug.Print "Hello " & text End Sub 

In the immediate window, if you enter

Proc1 

then "Hello World" prints. If you enter

Call Proc1 

then "Hello World" prints. If you enter

Proc2 "World" 

then "Hello World" prints. If you enter

Call Proc2 "World"  

you get a compile error. You would have to enter

Call Proc2("World") 
like image 66
Patrick Cuff Avatar answered Sep 27 '22 22:09

Patrick Cuff