我正在 Visual Studio 中编写 vb.net 代码,以便在 SAP B1 中添加内容。现在,我想选择一个选项按钮,根据用户选择的内容,我想获取此值并将其发送到另一个类中的另一个函数。我希望在用户按下确定按钮后立即执行此操作,因此我尝试在事件中执行此操作。
我为创建选项按钮编写的代码:
Dim optBtn As SAPbouiCOM.OptionBtn
'Dim oFrm As SAPbouiCOM.Form
Dim oUserdatasource As SAPbouiCOM.UserDataSource
oUserdatasource = oform2.DataSources.UserDataSources.Add("BD_resDS", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 1)
'Option 1
oItem = oform2.Items.Add("BD_rbRes", SAPbouiCOM.BoFormItemTypes.it_OPTION_BUTTON)
oItem.Left = 155
oItem.Top = 10
oItem.Height = 16
oItem.Width = 55
optBtn = oItem.Specific
optBtn.Caption = "Cheque"
optBtn.DataBind.SetBound(True, , "BD_resDS")
'Option 2
oItem = oform2.Items.Add("BD_rbPost", SAPbouiCOM.BoFormItemTypes.it_OPTION_BUTTON)
oItem.Left = 220
oItem.Top = 10
oItem.Height = 16
oItem.Width = 55
optBtn = oItem.Specific
optBtn.Caption = "Cash"
oItem.Visible = True
optBtn = oItem.Specific
optBtn.GroupWith("BD_rbRes")
optBtn.DataBind.SetBound(True, , "BD_resDS")
'Option 3
oItem = oform2.Items.Add("BD_rbPost2", SAPbouiCOM.BoFormItemTypes.it_OPTION_BUTTON)
oItem.Left = 280
oItem.Top = 10
oItem.Height = 16
oItem.Width = 75
optBtn = oItem.Specific
optBtn.Caption = "Credit Card"
oItem.Visible = True
optBtn = oItem.Specific
optBtn.GroupWith("BD_rbPost")
我在活动中写的代码是:
Public Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
Try
Dim fInv As SAPbouiCOM.Form
Dim omethod As SAPbouiCOM.Item
Dim opaymeth As SAPbouiCOM.OptionBtn
Dim paymeth As String
'If pVal.ItemUID = "1" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED And pVal.BeforeAction = True And pVal.ActionSuccess = False And pVal.FormUID = "60006" Then
'End If
'Events of the Blanket Agreement form
If (FormUID = "Choose") Then
If (pVal.BeforeAction = False) Then
' Click on Add Row
If (pVal.ItemUID = "1") And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) Then
fInv = SBO_Application.Forms.Item(FormUID)
omethod = fInv.DataSources.UserDataSources.Item("BD_resDS").ValueEx
opaymeth = omethod.Specific
paymeth = opaymeth.Value.ToString()
SBO_Application.MessageBox(paymeth)
If paymeth <> "" And paymeth <> Nothing Then
Dim paym As New payment(SBO_Application, oCompany)
paym.pay(paymeth)
End If
End If
End If
End If
Catch ex As Exception
'SBO_Application.MessageBox(er.Message)
SBO_Application.MessageBox(ex.Message)
End Try
End Sub
现在,我在SAP B1中遇到的错误是:
无法转换对象&#39; System.String&#39;输入&#39; SAPbouiCOM.Item&#39;
答案 0 :(得分:0)
omethod = fInv.DataSources.UserDataSources.Item("BD_resDS").ValueEx
.ValueEx似乎返回一个String,所以我猜你只需要删除它
omethod = fInv.DataSources.UserDataSources.Item("BD_resDS")
另一个很好的例子,为什么你应该总是打开Option Strict ON;)
答案 1 :(得分:0)
你已经宣布了 Dim omethod As SAPbouiCOM.Item
并将其分配给字符串值 omethod = fInv.DataSources.UserDataSources.Item(&#34; BD_resDS&#34;)。ValueEx
声明字符串变量并为其赋值
Dim tmpval as string =&#34;&#34; tmpval = fInv.DataSources.UserDataSources.Item(&#34; BD_resDS&#34;)。ValueEx
试试这个