on 07-17-2008 3:16 PM
Hi all,
In all the user forms I've developed, every time I click the "Cancel" button in a ChooseFromList form, my add-on stops responding. Can some one help me? I've posted some code bellow.
Could it have to do with not setting the BubbleEvent property?
Calling a sub to handle the event.
Case SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST
If pVal.FormTypeEx = "frmNR" Then FormNRCFL(oCompany, oApplication, FormUID, pVal, BubbleEvent)
Public Sub FormFolhaCFL(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, _
ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean)
Dim oCFLEvent As SAPbouiCOM.IChooseFromListEvent = pVal
Dim sCFL_ID As String = oCFLEvent.ChooseFromListUID
Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(sCFL_ID)
oForm = oApplication.Forms.GetForm(pVal.FormTypeEx, pVal.FormTypeCount)
...
If pVal.ItemUID = "PrcCode" Or pVal.ItemUID = "PrcName" Then
Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
If oCFLEvent.BeforeAction = False Then
If (Not oDataTable Is Nothing) And oDataTable.Columns.Count <> 0 And oDataTable.Rows.Count <> 0 Then
Try
With oForm.DataSources.DBDataSources.Item("@ADAT_FOLHA")
.SetValue("U_PrcCode", .Offset, oDataTable.GetValue("U_PrcCode", 0))
.SetValue("U_PrcName", .Offset, oDataTable.GetValue("U_PrcName", 0))
.SetValue("U_CardCode", .Offset, oDataTable.GetValue("U_CardCode", 0))
.SetValue("U_CardName", .Offset, oDataTable.GetValue("U_CardName", 0))
End With
If oForm.Mode <> BoFormMode.fm_ADD_MODE Then oForm.Mode = BoFormMode.fm_UPDATE_MODE
Catch ex As Exception
oApplication.MessageBox("CFLEvent(Form: " & pVal.FormTypeEx & ", " & "Item: " & pVal.ItemUID & ")" _
& vbCrLf & "Erro: " & oCompany.GetLastErrorCode.ToString & ", " & ex.Message.ToString)
End Try
End If
End If
End If
Thanks in advanced.
Best regards,
Vítor Vieira
Hi
Try using the following
Public Sub FormFolhaCFL(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application, _
ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean)
Dim oCFLEvent As SAPbouiCOM.IChooseFromListEvent = pVal
Dim sCFL_ID As String = oCFLEvent.ChooseFromListUID
Dim oCFL As SAPbouiCOM.ChooseFromList = oForm.ChooseFromLists.Item(sCFL_ID)
oForm = oApplication.Forms.GetForm(pVal.FormTypeEx, pVal.FormTypeCount)
...
Dim strValue1 As String, strValue2 As String, strValue3 As String, strValue4 As String
Try
strValue1 = oDataTable.GetValue("U_PrcCode", 0)
strValue2 = oDataTable.GetValue("U_PrcName", 0)
strValue3 = oDataTable.GetValue("U_CardCode", 0)
strValue4 = oDataTable.GetValue("U_CardName", 0)
Catch ex As Exception
'do nothing
End Try
If pVal.ItemUID = "PrcCode" Or pVal.ItemUID = "PrcName" Then
Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
If oCFLEvent.BeforeAction = False Then
If (Not oDataTable Is Nothing) And oDataTable.Columns.Count 0 And oDataTable.Rows.Count 0 Then
Try
With oForm.DataSources.DBDataSources.Item("@ADAT_FOLHA")
.SetValue("U_PrcCode", .Offset, strValue1)
.SetValue("U_PrcName", .Offset, strValue2)
.SetValue("U_CardCode", .Offset, strValue3)
.SetValue("U_CardName", .Offset, strValue4)
End With
If oForm.Mode BoFormMode.fm_ADD_MODE Then oForm.Mode = BoFormMode.fm_UPDATE_MODE
Catch ex As Exception
oApplication.MessageBox("CFLEvent(Form: " & pVal.FormTypeEx & ", " & "Item: " & pVal.ItemUID & ")" _
& vbCrLf & "Erro: " & oCompany.GetLastErrorCode.ToString & ", " & ex.Message.ToString)
End Try
End If
End If
End If
The problem is that when the user clicks Cancel, the code still tries to assign values. With the try-catch you control this by leaving the strings blank.
Hope it works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Neftali,
Thanks!
You can imagine how many times I've traced the code step-by-step and just didn't see the problem...
Previously
If pVal.ItemUID = "ItemCode" Or pVal.ItemUID = "ItemName" Then
Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
If oCFLEvent.BeforeAction = False Then
If Not oDataTable Is Nothing And oDataTable.Rows.Count <> 0 And oDataTable.Columns.Count <> 0 Then
Try
With oForm.DataSources.DBDataSources.Item("@ADAT_FOLHA")
.SetValue("U_ItemCode", .Offset, oDataTable.GetValue("ItemCode", 0))
.SetValue("U_ItemName", .Offset, oDataTable.GetValue("ItemName", 0))
End With
If oForm.Mode <> BoFormMode.fm_ADD_MODE Then oForm.Mode = BoFormMode.fm_UPDATE_MODE
Catch ex As Exception
oApplication.MessageBox("CFLEvent(Form: " & pVal.FormTypeEx & ", " & "Item: " & pVal.ItemUID & ")" _
& vbCrLf & "Erro: " & oCompany.GetLastErrorCode.ToString & ", " & ex.Message.ToString)
End Try
End If
End If
End If
End If
Now
If pVal.ItemUID = "ItemCode" Or pVal.ItemUID = "ItemName" Then
Dim oDataTable As SAPbouiCOM.DataTable = oCFLEvent.SelectedObjects
If oCFLEvent.BeforeAction = False Then
If Not oDataTable Is Nothing Then
If oDataTable.Rows.Count <> 0 And oDataTable.Columns.Count <> 0 Then
Try
With oForm.DataSources.DBDataSources.Item("@ADAT_FOLHA")
.SetValue("U_ItemCode", .Offset, oDataTable.GetValue("ItemCode", 0))
.SetValue("U_ItemName", .Offset, oDataTable.GetValue("ItemName", 0))
End With
If oForm.Mode <> BoFormMode.fm_ADD_MODE Then oForm.Mode = BoFormMode.fm_UPDATE_MODE
Catch ex As Exception
oApplication.MessageBox("CFLEvent(Form: " & pVal.FormTypeEx & ", " & "Item: " & pVal.ItemUID & ")" _
& vbCrLf & "Erro: " & oCompany.GetLastErrorCode.ToString & ", " & ex.Message.ToString)
End Try
End If
End If
End If
End If
The problem was I was calling the oDataTable.Rows.Count() method when the oDataTable object was null (or Nothing), and this wasn't throwing a NullReferenceException...
Problem solved. You get the cookie.
Best Regards,
Vítor Vieira
User | Count |
---|---|
101 | |
14 | |
10 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.