Microsoft Office Tutorials and References
In Depth Information
Testing and Debugging Your Functions
Figure 23-7: Using the VB Editor Immediate window to display results while a function is running.
Calling the function from a Sub procedure
Another way to test a Function procedure is to call the function from a Sub procedure. To do
this, simply add a temporary Sub procedure to the module and insert a statement that calls your
function. This is particularly useful because runtime errors display as they occur.
The following Function procedure contains a runtime error. As I noted previously, the runtime
errors don’t display when testing a function by using a worksheet formula. Rather, the function
simply returns an error (#VALUE!).
Function REVERSETEXT(text) As String
‘ Returns its argument, reversed
Dim TextLen As Long, i As Long
TextLen = Len(text)
For i = TextLen To 1 Step -1
Next i
End Function
Search JabSto ::

Custom Search