Re: Calling a Function or a Procedure



"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..."

.



Relevant Pages

  • Re: Calling a Function or a Procedure
    ... > Which format to use for Sub procedures is a matter of style. ... > difference when the "correct" syntax is used. ... > parameter is ByRef then any changes made to the value in MySub are lost ... 'Gotcha' that Bob pointed out - most programmers avoid it like the plague. ...
    (microsoft.public.vb.general.discussion)
  • Re: Syntax error with dates
    ... I think the problem lies with the date format in the input field. ... links to an access database. ... response to the effect there is a syntax error in the date. ...
    (microsoft.public.inetserver.asp.db)
  • Comma in query expression
    ... I believe that it is the format of the textfield, but I don't know how to fix ... Syntax error in query expression '=Brady, Tom'. ...
    (microsoft.public.access.queries)
  • Re: Receiving 3077 Date syntax error from international users
    ... "Jezebel" wrote in message ... You should always explicitly format dates for> inclusion in SQL strings ... ... >> My software application uses some DAO fields with the type dbDate. ... >> However many of my international users have been getting the following> error:>> 3077 Syntax error in date in expression. ...
    (microsoft.public.vb.database.dao)
  • Re: Inserting date datatypes via ado.net
    ... AFAIK when inserting in a datetime column, ... Remember a date is a DATE, and it does not have any format. ... When a date is represented in string, it has be in a format. ... > I get the same exact "Syntax error converting datetime from character ...
    (microsoft.public.dotnet.general)