Solved

Cannot use parentheses when calling a sub

Posted on 2006-06-23
13
699 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 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…
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…

867 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

18 Experts available now in Live!

Get 1:1 Help Now