程序是否成功结束时在文本框中显示消息

问题描述

我有下面的代码,当它运行更新 14 个表时,想知道如何使用下面模板中的文本框显示 msg 显示订阅是否成功结束。

[Private Sub Command0_Click()

   'Sub 1
    A_Forecast
    
    'Text Box showing the msg OK or Failed
    A_ForecastTxt "OK" or "Not"

   'Sub 2
    B_Forecast
    
    'Text Box showing the msg OK or Failed
    B_ForecastTxt "OK" or "Not"

   
End Sub][1]

enter image description here

解决方法

把 subs 变成 functions 因为它们可以返回一个值:

Private Sub Command0_Click()

    Dim Success As Boolean

    ' Function 1
    Success = A_Forecast
    
    ' Text box showing the msg OK or failed
    MsgBox IIf(Success,"OK","Failed")

    ' Function 2
    Success = B_Forecast
    
    ' Text box showing the msg OK or failed
    MsgBox IIf(Success,"Failed")
   
End Sub

示例:

Public Function A_Forecast() As Currency

    Dim Result As Currency
    Dim Something As Boolean

    ' Your code:
    Something = True ' or False

    If Something = True Then
        Result = 100
    Else
        Result = 200
    End If

    A_Forecast = Result

End Function