Function Explained

Function GetUserName
'Prompts the user for his name. If the user refuses to provide
''his name five times, we give up and return a zero-length string.
Dim UserName
Dim TryAgain
Dim LoopCount
LoopCount = 1
Do
TryAgain = "No"
UserName = InputBox("Please enter your name:")
UserName = Trim(UserNAme)
If UserName = " " Then
If LoopCount > 5 Then
UserName = " "
TryAgain = "No"
Else
MsgBox "You must enter your name."
TryAgain = "Yes"
End If
LoopCount = LoopCount + 1
Loop While TryAgain = "Yes"
GetUserNAme = UserNAme
End Function

The first thing to take note of here are the first and last line. The first line defines the beginning of the function and gives it a name. The last line defines the end of the function. Based on our earlier discussion of code blocks, this should be a familiar convention by now. In a sense, a procedure is nothing but a special kind of code block. We have to tell the script engine where it begins, and where it ends. Notice that we have given the function a clear, useful name that precisely described what this function does. Giving your procedure good name is a key to writing programs that are easy to read and maintain.

First
Next