Connecting Tech Pros Worldwide Help | Site Map

Sub won't accept parentheses around arguments

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 28th, 2007, 01:45 PM
Lyn
Guest
 
Posts: n/a
Default Sub won't accept parentheses around arguments

Can anyone explain this for me?

A sub procedure can be called with or without parentheses around the
arguments. By personal convention, I normally use parentheses. I am in
the middle of a fairly large project (for me), happily using parentheses
everywhere -- until this happened:

The following sub is defined in a class module.

Public Sub DeleteXXRecord(lngEORekNombro As Long, lngXXRekNombro As Long)
[..code..]
End Sub

In another (form) module, I call the sub thus:

Dim A As Long
Dim B As Long

A = [some long number]
B = [some long number]

DeleteXXRecord(A, B)

While typing this last line, Intellisense seems to be quite happy with what
I am typing. But as soon as I newline after entering the line, it turns
red. Doing a compile gives me "Syntax error" on this line.

I have been agonizing over what could be wrong with such a simple sub call,
trying to cut down the code to the bare basics -- all to no avail. Until
in desperation I decided to try deleting the parentheses -- thus:

DeleteXXRecord A, B

Lo and behold, this actually compiled error-free. The only sub call in the
whole project without parentheses!

I know that many people don't use use parentheses with sub calls. I do it
mainly for consistency with function calls (I've gotten into the habit).
As far as I know, parentheses around a sub's arguments should always work.

Have I got this wrong somehow???

Thanks for any help,
Lyn.

  #2  
Old May 28th, 2007, 02:15 PM
UrbanSpaceman
Guest
 
Posts: n/a
Default Re: Sub won't accept parentheses around arguments

All you need in order to keep using parens is to 'call' the sub:

Call DeleteXXRecord(A, B)

"Lyn" <l.hancock@iiNet.net.auwrote in message
news:t2orusctal4l$.1xove5w6shju1.dlg@40tude.net...
Quote:
Can anyone explain this for me?
>
A sub procedure can be called with or without parentheses around the
arguments. By personal convention, I normally use parentheses. I am in
the middle of a fairly large project (for me), happily using parentheses
everywhere -- until this happened:
>
The following sub is defined in a class module.
>
Public Sub DeleteXXRecord(lngEORekNombro As Long, lngXXRekNombro As Long)
[..code..]
End Sub
>
In another (form) module, I call the sub thus:
>
Dim A As Long
Dim B As Long
>
A = [some long number]
B = [some long number]
>
DeleteXXRecord(A, B)
>
While typing this last line, Intellisense seems to be quite happy with
what
I am typing. But as soon as I newline after entering the line, it turns
red. Doing a compile gives me "Syntax error" on this line.
>
I have been agonizing over what could be wrong with such a simple sub
call,
trying to cut down the code to the bare basics -- all to no avail. Until
in desperation I decided to try deleting the parentheses -- thus:
>
DeleteXXRecord A, B
>
Lo and behold, this actually compiled error-free. The only sub call in
the
whole project without parentheses!
>
I know that many people don't use use parentheses with sub calls. I do it
mainly for consistency with function calls (I've gotten into the habit).
As far as I know, parentheses around a sub's arguments should always work.
>
Have I got this wrong somehow???
>
Thanks for any help,
Lyn.

  #3  
Old May 28th, 2007, 02:45 PM
missinglinq via AccessMonster.com
Guest
 
Posts: n/a
Default Re: Sub won't accept parentheses around arguments

In other words you can invoke a sub in two different ways

Call DeleteXXRecord(A, B)

or

DeleteXXRecord A, B

but you can't mix and match i.e.

DeleteXXRecord(A, B) or Call DeleteXXRecord A, B

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200705/1

  #4  
Old May 28th, 2007, 11:15 PM
Lyn
Guest
 
Posts: n/a
Default Re: Sub won't accept parentheses around arguments

On Mon, 28 May 2007 14:34:53 GMT, missinglinq via AccessMonster.com wrote:
Quote:
In other words you can invoke a sub in two different ways
>
Call DeleteXXRecord(A, B)
>
or
>
DeleteXXRecord A, B
>
but you can't mix and match i.e.
>
DeleteXXRecord(A, B) or Call DeleteXXRecord A, B
Thanks to both who responded. I have researched the Call statement which
confirms what you have said. I have also now tried:

Call DeleteXXRecord (A, B)

and it works as advertised.

It is strange that in three years of using the parentheses format without
the "Call" statement, it has always worked perfectly -- up until now. VBA
must be loose enough to allow this erroneous syntax in most cases.

However, the writing is on the wall -- I am going to have to change my
style of calling Subs!

Thanks for the help!

Lyn.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.