Solved

Cannot use parentheses when calling a sub

Posted on 2006-06-23
13
717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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