Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot use parentheses when calling a sub

Posted on 2006-06-23
13
Medium Priority
?
730 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 80 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 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