VBA Debugging Tool Debug.Print

Source: Internet
Author: User

Iamlaosong

Baidu a bit. Very easy to find Debug.Print explain and use introduction. It's actually very simple. is to display the results of the code run in the immediate form, without affecting the program running. during the debugging of a VBA program, it is often necessary to monitor the value of the variable, although MsgBox can also complete this function, but with Debug.Print Displays the value of a variable or expression. Have a lot of advantages. Details such as the following:

1, does not affect the program operation. despite MsgBox can also display code running results, but each time to press OK button to continue, encountered large circular statement simply can not be carried out;

2, after the completion of the program debugging. These debug statements should be masked. But even if there is a legacy of Debug.Print does not affect user use. MsgBox is not good;

3, the biggest advantage is: for the value of the variable, can be in the "immediate form" slowly study, can be copied out of the study, for example, we want to synthesize an SQL statement. But there was an error in the operation, where was it wrong? The variables and values in the program are mixed together and it's hard to find the wrong point. Especially when the numbers and parentheses are large. Copy the synthesized SQL statement and run it, you can easily find the problem,MsgBox not.

By the way, right away. Form ( Press Ctrl+g or menu to select ), in addition to displaying the running results of the Debug.Print. The form is also able to enter statements directly during debugging. Press ENTER to display the result of the statement, you can also use the "? Variable name to display the value of the variable (although the value of the variable is displayed when the mouse is over the variable, assuming that the value is too long to be displayed). For example, suppose you have a variable that is mystr, and you can enter the following example in the immediate form:

? MyStr

?

Left (mystr,5)

? InStr (MyStr, ":")

If Len (mystr) >0 Then MsgBox mystr


VBA Debugging Tool Debug.Print

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.