The Debug Print Statement

As you already know, the ? character is short for Debug.Print, and you've seen how easy it is to use both commands directly in the Immediate window. That's not the only place you can use Debug.Print statements, The following code illustrates how Debug.Print can be used within a module, so you can imagine how it can be helpful for testing and debugging.

Sub FunWithStringsAndNumbers() Dim strBikes As String Dim strCost As String Dim strCustomerName As String Dim intBikes As Integer Dim curCost As Currency strBikes = "5" strCost = "100"

strCustomerName = "The ""W"" Hotel, New York City" intBikes = 5 curCost = 100

Debug.Print strBikes + strCost Debug.Print intBikes + curCost Debug.Print strCustomerName End Sub

This code produces the following results in the Immediate window:

5100 105

The "W" Hotel, New York City

You can use the Debug.Print statement within any procedure to display results of calculations or values of variables in the Immediate window. That's a quick way to confirm that your code is achieving the desired results.

Was this article helpful?

0 0

Post a comment