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()
下,在此按钮的属性中,单击 forecolor设置为值-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很新。
谢谢和问候
答案 0 :(得分:0)
正如joe所指出的那样,返回值是一个错误号,因此更新答案以反映这一点,而不仅仅是一个随机的负整数。
如果这个值被直接用于改变任何东西,那么将它转换为c#你认为合适的最佳方式可能是安全的。在长期使用中没有使用过VBA,但它充满了有趣的东西< / p>
<强>更新强> 存储的删除程序名称不相同。代码中的那个与您提供的存储过程代码段不同。
答案 1 :(得分:0)
看起来函数cnn.Execute
中的行aaExecuteSP
引发错误-2147483630。 aaExecuteSP
中的错误处理程序将此错误代码返回给调用者,但丢弃了许多其他有用的信息,这些信息将帮助您调试此错误:
Err.Message
cnn.Errors collection
我建议您逐步使用调试器,在aaExecuteSP
中的“ErrGetData:”后面的行中断,并检查这些属性。
BTW我认为错误代码恰好与按钮的ForeColor属性(vbButtonText = &H80000012 = -2147483630)
相同只是巧合。