0
Private Sub CmdValid_Click()
On Error GoTo ErrValid:
Dim LngExec As Long
Dim varCie

Dim ret As VbMsgBoxResult
Dim StrSql
Dim DblBalance
    If Me.SF.Form.Dirty Then
        Me.SF.Form.Refresh
    End If
    DblBalance = aaRound(aaRound(Me.SF.Form.TxtCreditTotal.Value, 2) - aaRound(Me.SF.Form.TxtDebitTotal.Value, 2), 2)


    If DblBalance <> 0 Then

        MsgBox "Credit must be equal to credit. Press Delete if you want to delete this journal entry, or enter the appropriate values", vbCritical, "Validation refused"
    Else
    '---- We have to create the two record into the General ledger detail

        StrSql = "EXEC SpValidGenLedDet " & str(Me.GLHCode)
        LngExec = aaExecuteSP(StrSql)
        If LngExec = 0 Then
            DoCmd.SetWarnings (False)
            StrSql = "EXEC SpDelGenLedDetTmp " & str(Me.GLHCode)
            LngExec = aaExecuteSP(StrSql)
            DoCmd.SetWarnings (True)
            ret = MsgBox("This entry is successfully validated. Do you want to create another entry ?" & Chr(13) & Chr(10) & "click YES to add a new one , NO to close this form", vbInformation + vbYesNo, "validation accepted")
            If ret = vbYes Then
                varCie = Me.CboGlHInternalCie
                DoCmd.GoToRecord , , acNewRec
                If Not IsNull(varCie) Then
                    Me.GlHInternalCie = CLng(varCie)
                End If
            Else
                DoCmd.Close acForm, Me.Name
            End If
        Else
            MsgBox "There was an error while Writing the accounting lines into the General ledger, retry to validate or press delete to cancel the transaction"
        End If
    End If
finValid:
    Exit Sub
ErrValid:
    MsgBox "Error during validation", vbCritical, "Error"
    Resume finValid

End Sub

我有一个 VBA 代码,我需要将其转换为上面给出的 c# 但是我无法理解为什么某些事情正在完成或发生

例如,上面的代码在Private Sub CmdValid_Click()此按钮的属性下,单击前景色设置为 -2147483630 的值。当我执行代码并检查断点时,我在 LngExec 中得到值 -2147483630

然而,SpDelGenLedDetTmp 过程只是一个带有 where 子句的简单删除过程

    **

    /****** Object:  StoredProcedure [dbo].[SpDelGenLedTmp]    Script Date: 10/28/2012 12:27:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    ALTER  PROCEDURE [dbo].[SpDelGenLedTmp]
        (@GHDHeader_1   [int])
    AS DELETE [ABOUSQL].[dbo].[TblGenLedDetTmp] 
    WHERE 
        ( [GHDHeader]    = @GHDHeader_1)

**

Function aaExecuteSP(StrSql) As Long
On Error GoTo ErrGetData
Dim cnn As ADODB.Connection
Dim isok
Set cnn = aaDbConnect()

cnn.Execute (StrSql)

aaExecuteSP = 0
FinGetData:
    Exit Function
ErrGetData:
   If Err.Number <> 0 Then
    aaExecuteSP = Err.Number
End If
    Resume FinGetData



End Function

任何帮助将不胜感激我对 VBA 很陌生

谢谢并恭祝安康

4

2 回答 2

0

正如 joe 所指出的,所看到的返回值是一个错误号,因此更新答案以反映这一点,而不仅仅是一个随机负整数。

如果该值不直接用于更改任何内容,那么将其转换为 c# 你认为最合适的方式可能是安全的。很久没有使用 VBA,但它充满了有趣的东西

更新 删除的存储过程名称不同。代码中的那个与您提供的存储过程片段不同。

于 2012-10-28T07:45:59.463 回答
0

看起来cnn.Execute函数中的行aaExecuteSP正在引发错误-2147483630。中的错误处理程序aaExecuteSP将此错误代码返回给调用者,但会丢弃许多其他有用的信息,这些信息将帮助您调试:

Err.Message 
cnn.Errors collection

我建议您逐步使用调试器,在 "ErrGetData:" in 之后的行处中断aaExecuteSP,并检查这些属性。

顺便说一句,我认为错误代码恰好与按钮的 ForeColor 属性相同(即vbButtonText = &H80000012 = -2147483630)只是一个巧合

于 2012-10-28T09:21:38.950 回答