在運行時在 VBA 中顯示所有變量及其值 (Show all variables and their values in VBA during runtime)


問題描述

在運行時在 VBA 中顯示所有變量及其值 (Show all variables and their values in VBA during runtime)

在我當前的 Access VBA 項目中,我創建了一個像控制台一樣工作的窗口,現在我正在嘗試添加顯示任何公共變量的可能性。它應該像這樣工作:

Show_var [variable_name]

所以它應該像在我可以輸入的直接窗口中一樣:

? pVar.variable_A

我發現使用

Application.VBE.ActiveVBProject.VBComponents(11).CodeModule.CountOfLines

我可以顯示模塊或表單中的行數,所以我想也許我可以在那裡找到變量,循環遍歷它們,當找到正確的變量時,可以顯示它的值。OFC 我可以創建一個包含所有變量的 Select Case 語句,但這不是我想要的方式,因為它很複雜,並且每次更新我的公共變量列表時都必須更改。</p >


參考解法

方法 1:

There are so many problems that I think you are out of luck. Let me just list some of them:

  • There is no way to get a list of all variables ‑ that would mean you would need access to the internal symbol table.

  • As a consequence, you would have to read the code (CodeModule lets you read the code of a module), and write an own parser to fetch all declarations (hopefully you use Option Explicit)

  • AFAIK, the is no method that can access the content of a variable via it's name.

  • Even if there would be any such method: What would you do with different data types, arrays and especially with objects.

  • If a user runs into problems, often it is a runtime error. If you don't handle that errors with some kind of error handler, the only option if a user cannot enter the debugger is to press "End" ‑ which would destroy the content of all variables.

  • You have to deal with scope of variables, you can have several variables with the same name and you will likely have lots of variables that are out of scope in the moment you want to dump them.

(by vba‑nerdFunThomas)

參考文件

  1. Show all variables and their values in VBA during runtime (CC BY‑SA 2.5/3.0/4.0)

#runtime #global-variables #vba






相關問題

通過java運行的執行程序似乎超時? (Executed programs run through java seem to time out?)

Kesalahan NullPointerException dalam kode Java saya. (NullPointerException errors in my Java code.)

Hentikan proses anak ketika proses induk berhenti (Stop child process when parent process stops)

Атрымаць шлях выканання кансольнага скрыпта Python (Get the runpath of a python console-script)

選擇不包含主要類型 - 錯誤 (Selection does not contain main type - error)

在活動之間使用意圖錯誤 (using intents between activities error)

在運行時使用 Spring 在表中創建新字段 (Create new field into a table with Spring at runtime)

如何添加運行時超時以防止 java.net.SocketTimeoutException? (How do I add a runtime timeout to prevent java.net.SocketTimeoutException?)

我有什麼方法可以覆蓋 Java 中的系統屬性嗎? (Do I have any method to override System Properties in Java?)

如何計算此代碼的時間複雜度? (How can I compute the time complexity of this code?)

運行 .exe 文件生成 bt jar2exe 軟件時出現 java runtime environment not found 錯誤 (Getting java runtime enviroment not found error while running .exe file produced bt jar2exe software)

在運行時在 VBA 中顯示所有變量及其值 (Show all variables and their values in VBA during runtime)







留言討論