Calling Methods That Return Values

If a method returns a value, you can call the method with parentheses or without them:

• Calling a method with parentheses returns either a value or a reference to an object, so you must do something with the result or an error will occur. The following code returns a reference to the Task object it just created:

ActiveProject.Tasks.Add("Write chapter", 3)

Without additional code to work with the returned object, this code will result in a syntax error.

• Calling a method without parentheses means that the method takes action and discards the return value. The following code creates a task:

ActiveProject.Tasks.Add "Write chapter", 3

For more information about methods that return values (functions), see "Understanding Procedures" later in this chapter on page 888.

For more information about working with optional arguments, see "Named Arguments" later in this chapter on page 897.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment