我很难理解为什么这总是返回一个空变量
Private Function checkEnvelopeStatus(aEnvelopeID As String) As String
Dim lEnvelopeStatusMessage As String
Try
Dim lEnvelopeStatus = mDsapi.RequestStatusEx(aEnvelopeID)
lEnvelopeStatusMessage = "Subject:" & lEnvelopeStatus.Subject & vbCrLf & "Status Code: " & lEnvelopeStatus.Status
Catch ex As Exception
MessageBox.Show(ex.StackTrace, ex.Message)
End Try
Return lEnvelopeStatusMessage
End Function
然而,这将返回我想要的消息
Private Function checkEnvelopeStatus(aEnvelopeID As String) As String
Dim lEnvelopeStatusMessage As String
Try
Dim lEnvelopeStatus = mDsapi.RequestStatusEx(aEnvelopeID)
aEnvelopeID = "Subject:" & lEnvelopeStatus.Subject & vbCrLf & "Status Code: " & lEnvelopeStatus.Status
Catch ex As Exception
MessageBox.Show(ex.StackTrace, ex.Message)
End Try
Return aEnvelopeID
End Function
似乎在我的 TRy 捕获关闭后,当它是函数本地变量时,字符串的值正在被清除。然而,当我用传入的参数替换它时,我能够保留 Try Catch 外部的字符串?我主要是 C#/C++ 开发人员,所以这对我来说是令人困惑的行为。谁能解释为什么会发生这种情况?
这是上面代码的更干净的版本
Public Function foo(a As String) As String
Dim b As String
Try
b = "banana:"
Catch ex As Exception
End Try
Return b
End Function
它表现出相同的行为。