新增監看運算式Add a watch expression

監看運算式是您定義要監視在[監看] 視窗](../../reference/user-interface-help/watch-window.md)中的運算式。A watch expression is an expression that you define to be monitored in the Watch window. 當您的應用程式進入中斷模式時,在其中您可以觀察到其值的監看] 視窗中會出現您所選取的監看運算式。When your application enters break mode, the watch expressions you selected appear in the Watch window where you can observe their values.

新增監看運算式To add a watch expression

  1. 在**偵錯] 功能表中,選擇 [新增監看式On the Debug menu, choose Add Watch. 新增監看** 對話方塊會顯示。The Add Watch dialog box is displayed.

  2. 如果已在[程式碼] 視窗](../../reference/user-interface-help/code-window.md)中選取運算式,它會自動顯示運算式] 方塊中。If an expression is already selected in the Code window, it is automatically displayed in the Expression box. 顯示沒有運算式時,輸入您想要評估的運算式。If no expression is displayed, enter the expression you want to evaluate. 運算式可以是變數屬性、 函數呼叫或任何其他有效的運算式。The expression can be a variable, a property, a function call, or any other valid expression.

  3. 選取範圍的評估運算式的 [內容] 群組中選取的模組程序的內容。Select a module or procedure context in the Context group to select the range for which the expression will be evaluated.

    注意

    選取最窄範圍符合您的需求。Select the narrowest scope that fits your needs. 選取所有程序] 或 [全部模組會減慢模組執行明顯,因為每個陳述式執行後評估的運算式。Selecting all procedures or all modules can slow down module execution considerably, because the expression is evaluated after execution of each statement. 如果您選取內容的特定程序,執行會影響僅時程序中的作用中的程序呼叫清單。If you select a specific procedure for a context, execution is affected only while the procedure is in the list of active procedure calls. 呼叫堆疊從功能表選擇 [檢視 以顯示作用中的程序的清單。Choose Call Stack from the View menu to display the list of active procedures.

  4. 若要定義系統如何反應監看運算式的監看式類型] 群組中選取一個選項。Select an option in the Watch Type group to define how the system responds to the watch expression.

    • 若要顯示監看運算式的值,請選擇 [監看運算式To display the value of the watch expression, choose Watch Expression.

    • 若要停止執行,如果運算式評估為True,請選擇 [自動換行時值為 TrueTo stop execution if the expression evaluates to True, choose Break When Value is True.

    • 若要停止執行,運算式的值變更時,請選擇值變更時自動換行To stop execution when the value of the expression changes, choose Break When Value Changes.

  5. 選擇 [確定]****。Choose OK.

另請參閱See also

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.