Solved

Cannot use parentheses when calling a sub

Posted on 2006-06-23
13
697 Views
Last Modified: 2008-03-10
Hi
I try to do this

if(websiteStatus = 1) then

    emailwarning(Trim(CStr(website_rows.fields("website").value)), GetDate())

  end if

Function emailWarning(problemUrl,problemTime)

Any ideas?
0
Comment
Question by:boofulls
  • 3
  • 2
  • 2
  • +2
13 Comments
 
LVL 8

Expert Comment

by:wraith821
ID: 16967959
Sub emailWarning(problemUrl,problemTime)
0
 
LVL 8

Expert Comment

by:wraith821
ID: 16967966
also change getdate() to Now
0
 
LVL 13

Accepted Solution

by:
jmundsack earned 20 total points
ID: 16968003
When calling a sub (or calling a function without assigning its return value) you should omit the parentheses, or use the Call statement:

If (websiteStatus = 1) Then
    emailWarning Trim(CStr(website_rows.fields("website").value)), GetDate()
End If

-or-

If (websiteStatus = 1) Then
    Call emailWarning(Trim(CStr(website_rows.fields("website").value)), GetDate())
End If

This is because without the Call syntax, VB thinks what you want to do is evaluate the contents of the parentheses as an expression, which in your case would be an invalid expression (arg1, arg2 is not a valid expression).

HTH-Jon
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16968056
The use of functions instead of sub is usually to obtain a return value i.e. you get that function to return a value to indicate a failure or to obtain a value

If u dont want a return value, do what wraith821 has said, change from function to sub

I only use functions if I want to return a value

rv = emailWarning(Trim(CStr(website_rows.fields("website").value)), GetDate())
if rv = ... then

if u stick with leaving it called as a function, and dont want a return value then do what jmundsack says


those experts have already given you the answers, Ive just explained one difference between function and sub



0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 13

Expert Comment

by:jmundsack
ID: 16968298
Whether you leave it as a function or a sub, you need to do what I said when calling it.  If you leave the parentheses there you'll get a syntax error.
0
 

Expert Comment

by:pckben
ID: 16980046
In VB, your idea should be expressed like this:
...
    if websiteStatus = 1 then
        emailwarning Trim(CStr(website_rows.fields("website").value)), GetDate()
    end if
...
Sub emailWarning(problemUrl as String, problemTime as Date)
...
End Sub
0
 
LVL 12

Expert Comment

by:jkaios
ID: 16981289
Hello everyone!

By looking at the title of the question, I completely agree with "jmundsack".
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17294100
The answer from jmundsack is the one that should be accepted. It explains how to do it and the 2 ways to do it
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17306906
No objections from me
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now