473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sub won't accept parentheses around arguments

Lyn
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.
May 28 '07 #1
3 2537
All you need in order to keep using parens is to 'call' the sub:

Call DeleteXXRecord(A, B)

"Lyn" <l.*******@iiNet.net.auwrote in message
news:t2*****************************@40tude.net...
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.

May 28 '07 #2
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

May 28 '07 #3
Lyn
On Mon, 28 May 2007 14:34:53 GMT, missinglinq via AccessMonster.com wrote:
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.
May 28 '07 #4

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

Similar topics

47
by: Will Stuyvesant | last post by:
Hello all, So Zope still lives, yay. Well, I like that they use Python. <rant> What amazed me is they write that they "added types to the variables and hope that it will be added to the...
44
by: seberino | last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows. This causes confusion for 1 item tuples since (5) can be interpreted as a tuple OR as the number 5 in a mathematical...
5
by: FayeC | last post by:
Ok....I made the appropriate additions to the spaces commented and this is what I got now: currentDate = new Date; today =...
4
by: Steve | last post by:
Hi I have decided it is time to learn Javascript (I know PHP fairly well, so I thought it shouldn't be too difficult!!!) I have a couple of question though, which I can highlight with the...
7
by: zheetee | last post by:
<script type="text/vbscript"> sub setTextBoxValue(a1,a2) thedelete.deleteTextBox.value = a1 end sub </script> <td> <a href="#"...
3
by: John Goche | last post by:
Hello, I would like to know why the first three statements produce output whereas the last one does not. Also, should parentheses be included when constructing such an instance on the heap?...
6
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void...
11
by: rtalbot | last post by:
Can somebody clarify why: Given a simple template: template <class T> struct foo { }; This: foo<float> bar;
7
by: vlsidesign | last post by:
I am not sure how to think about parentheses. It seems when they are used alongside characters it indicates a function, like addTwoNums(). But is also is used to enforce which operators and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.