Microsoft Office Tutorials and References
In Depth Information
Testing and Debugging Your Functions
When this function is evaluated, a pop-up message box appears, once for each time through the
loop. The message box shows the current value of REVERSETEXT . In other words, this technique
enables you to monitor the results as the function is executed. Figure 23-6 shows an example.
Figure 23-6: Use a MsgBox statement to monitor the value of a variable as a Function procedure executes.
The information displayed in the series of message boxes shows that the text string is being built
within the loop, but the new text is being added to the beginning of the string, not the end. The
corrected assignment statement is
REVERSETEXT = REVERSETEXT & Mid(text, i, 1)
When the function is working properly, make sure that you remove all the MsgBox statements.
If you get tired of seeing the message boxes, you can halt the code by pressing
Ctrl+Break. Then, respond to the dialog box that’s presented. Clicking the End button
stops the code. Clicking the Debug button enters Debug mode, in which you can step
through the code line-by-line.
To display more than one variable in a message box, you need to concatenate the variables and
insert a space character between each variable. The following statement, for example, displays
the value of three variables ( x , y , and z ) in a message box:
MsgBox x & “ “ & y & “ “ & z
If you omit the blank space, you can’t distinguish the separate values.