Microsoft Office Tutorials and References
In Depth Information
Figure 24-7: Using the VB Editor Immediate window to display results while a function is running.
When your function is debugged, make sure that you remove the Debug.Print statements.
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 use-
ful because runtime errors display as they occur.
The following Function procedure contains a runtime error. As I noted previously, the runtime errors don't dis-
play 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
REVERSETEXT = REVERSETEXT And Mid(text, i, 1)
Next i
End Function
To help identify the source of the runtime error, insert the following Sub procedure:
Search JabSto ::




Custom Search