Re: Calling a Function or a Procedure
- From: "Bob Butler" <tiredofit@xxxxxxxxxx>
- Date: Sat, 26 Nov 2005 06:24:58 -0800
"Abhishake" <Abhishake@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8680C048-63AD-4AD5-AD81-AC5C4BB6F7B7@xxxxxxxxxxxxx
> Dear All,
>
> Please help me out in finding a the difference between two statement
> (1st statement and 2nd Statement)in Visual basic 6.0 ,while calling
> any procedure
>
> 1st Statement :
>
> call AnyProcedureName (Parameters 1,Parameter 2,Parameter 3)
>
> 2nd Statement :
> AnyProcedureName (Parameters 1,Parameter 2,Parameter 3)
>
> It would be appreciating if it is a deep disscussion.
Your second statement as written is not valid VB syntax but, in general,
there are two ways to call "Sub" procedures in VB:
CALL procedurename(argumentlist)
and
procedurename argumentlist
For "Function" procedures you can use the same methods as above and also use
returnvalue=procedurename(argumentlist)
and
If procedurename(argumentlist) Then
and otherwise use the "procedurename(argumentlist)" format in expressions
Which format to use for Sub procedures is a matter of style. There is no
difference when the "correct" syntax is used.
The problem comes in when you mix the two formats by omitting CALL and
trying to use the () characters anyway (this only works for procedures with
0 or 1 parameters; 2+ parameters results in a syntax error). When you code
something like
MySub (x)
VB sees that no CALL is used and assumes you are using the statement format
and interprets it as
CALL MySub((x))
To pass the value VB evaluates the expression "(x)" and passes the result.
If the parameter is ByVal then there is no effective difference. If the
parameter is ByRef then any changes made to the value in MySub are lost
because VB can't update the value of the expression (x) any more than it
could if you had used "MySub x+1" or any other expression. This can be
useful if you understand it and a great way to introduce a bug into your app
if yout don't.
The syntax error with multiple arguments comes up because if you try to use
MySub (x,y)
VB reads it as if you had entered
Call MySub((x,y))
but "(x,y)" is not a valid expression.
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
.
- Follow-Ups:
- Re: Calling a Function or a Procedure
- From: Ralph
- Re: Calling a Function or a Procedure
- Prev by Date: Re: Listbox / Database Question
- Next by Date: Re: For Your Amusement
- Previous by thread: Re: Calling a Function or a Procedure
- Next by thread: Re: Calling a Function or a Procedure
- Index(es):
Relevant Pages
|