Solved

Cannot use parentheses when calling a sub

Posted on 2006-06-23
13
705 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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