Understanding Procedures

Sub AddTask()

MsgBox strNewTask("Write chapter", 3) End Sub

The Sub and End Sub, Function and End Function statements define the boundaries of the sub or function. As you can see, the statement declaring the function declares it as a particular data type, whereas the sub does not.

This code contains several other items worth noting:

•( The function has two arguments, strName and intBefore, which are declared just like any other variables, even though they are part of the function declaration.

•( To return a value from a function, you must first assign a value to the name of the function, as in the following line:

strNewTask = "Success!"

•( The MsgBox function takes several arguments, one of which is a String that contains the text to display in the dialog box. (It is itself a function because it can return information about which button the user clicked; by calling it without parentheses, we're discarding the Integer value that it would otherwise return.) Instead of being supplied as text in quotes (a string literal) or even as a "traditional" variable, the argument is supplied as the return value of the function strNewTask.

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