Datasheet
Chapter 1: A Quick Introduction to Programming
23
 Else
 Greeting = “Hello, “ & YourName & “, great to meet you.”
 If YourName = “Fred” Then
 Greeting = Greeting & “ Nice to see you Fred.”
 End If
 End If
 MsgBox Greeting
 PromptUserName = YourName
End Function
   As you can see, calling the PromptUserName  function is pretty straightforward. Once you have written 
a procedure, calling it is no different than calling a built-in VBScript procedure. 
   Advantages to Using Procedures 
 Procedures afford several key advantages that are beyond the scope of this discussion. However, here 
are a few of the most important ones:
 ❑    Code such as that put in the PromptUserName  function can be thought of as “generic,” meaning 
that it can be applied to a variety of uses. Once you have created a discreet, well-defined, generic 
function such as 
PromptUserName , you are free to reuse it any time you want to prompt users 
for their name. Once you’ve written a well-tested procedure, you never have to write that code 
again. Any time you need it, you just call the procedure. This is known as code reuse.  
❑    When you call a procedure to perform a task rather than writing the code in-line, it makes that 
code much easier to read and maintain. Increasing the readability, and therefore the manageability 
and maintainability, of your code is a good enough reason to break a block of code out into its 
own procedure.  
❑    When code is isolated into its own procedure, it greatly reduces the effects of changes to that 
code. This goes back to the idea of the black box. As long as the procedure maintains its 
 predictable inputs and outputs, changes to the code inside of a procedure are insulated from 
harming the code that calls the procedure. You can make significant changes to the procedure, 
but as long as the inputs and outputs are predictable and remain unchanged, the code will 
work just fine.  
      Top-Down versus Event-Driven 
 Before you leave this introduction to programming, it may be helpful to point out that you will encounter 
two different models  of programming in this book: top-down and event-driven programs. The differences 
between the two have to do with the way you organize your code and how and when that code gets 
 executed at runtime. As you get deeper into programming in general, and VBScript in particular, this will 
become clearer, so don’t be alarmed if it doesn’t completely sink in right now. 
c01.indd 23c01.indd 23 8/27/07 7:45:25 PM8/27/07 7:45:25 PM










