阅读消息框中显示的信息

Read Information displayed in Message Box

我正在研究 Catia Automation

这种情况是,每当特定许可证不可用时,就会弹出一条消息说 no licences are available 并显示使用该许可证的部分用户列表。

有什么方法可以通过代码读取消息并将其用作字符串?

来自官方文档"CAA V5 Automation Coding Rules":

As a default behavior the interpreter will stop and display an error message box whenever an error is raised. When you want to take corrective actions on an error, disabling the automatic error handing mechanism using "On Error Resume Next" becomes mandatory.

这意味着您应该禁用默认错误处理,而是使用错误对象编写自定义逻辑 Err

Dim CATIA As Object
On Error Resume Next      ' Disable automatic error handling
    Set CATIA=GetObject(,"CATIA.Application")
    iErr = Err.Number     ' For BasicScript parser (Unix)
    If (iErr <> 0) Then   ' Manually handle all errors
       On Error Goto 0    ' Invalidates the Resume Next and clears the error
        set CATIA=CreateObject("CATIA.Application")
    End If
On Error Goto 0           ' Invalidates the Resume Next and clears the error

Err 是包含错误信息的错误对象。

您可以使用Err.Message、Err.description、Err.number获取信息

Sub yoursub
On Error goto error      ' goto error handling block
    Set CATIA=GetObject(,"CATIA.Application")

    // your code 

error:
Debug.print Err.Description  ' print description to immediate window
Debug.print Err.Source       ' print source of error to immediate window
Debug.print Err.Number       ' print error number to immediate window
End Sub