Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Using Split() and TrimEnd() functions

Hi,

Please see the attached images which explain my problem.

My codes are as follows:

Code 1 (for Suppliers)

=================

This code was generously provided by Former Member

and it works perfectly.

If (pVal.FormTypeEx = "120060805" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK And pVal.BeforeAction = False And pVal.ItemUID = "120000001" And pVal.ActionSuccess = True) Then

            '// 120060805 = Internal Reconciliation Form ; 120000001 =  Reconcile Button

oForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormTypeEx, pVal.FormTypeCount)

            Dim oMatrix As SAPbouiCOM.Matrix

oMatrix = oForm.Items.Item("120000039").Specific

            '// 120000039 =  SAP Matrix Table

            For oRowCnt As Integer = 1 To oMatrix.VisualRowCount

Dim oChkBox As SAPbouiCOM.CheckBox

oChkBox = oMatrix.Columns.Item("120000002").Cells.Item(oRowCnt).Specific

'// 120000002 =  CheckBox Column in SAP

If oChkBox.Checked = True Then

Dim oAmt2Recon As String = oMatrix.Columns.Item("120000027").Cells.Item(oRowCnt).Specific.value

'// 120000027 = Amount Column

                    Dim oResult As Double

Dim subValue() As String = oAmt2Recon.Split("(")

subValue(1) = subValue(1).TrimEnd(")")

If Not Double.TryParse(subValue(1), oResult) Then

'Error handling code here

End If

oCumTotal = oCumTotal + oResult

End If

            Next

           End If

Code 2 (for Customers)

==================

I adapted the above code to suit the Customers screen, but it does not work.

Could you help me write the correct code?

Thanks a lot

Leon Lai

If (pVal.FormTypeEx = "120060805" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK And pVal.BeforeAction = False And pVal.ItemUID = "120000001" And pVal.ActionSuccess = True) Then

            '// 120060805 = Internal Reconciliation Form ; 120000001 =  Reconcile Button

oForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormTypeEx, pVal.FormTypeCount)

            Dim oMatrix As SAPbouiCOM.Matrix

oMatrix = oForm.Items.Item("120000039").Specific

            '// 120000039 =  SAP Matrix Table

            For oRowCnt As Integer = 1 To oMatrix.VisualRowCount

Dim oChkBox As SAPbouiCOM.CheckBox

oChkBox = oMatrix.Columns.Item("120000002").Cells.Item(oRowCnt).Specific

'// 120000002 =  CheckBox Column in SAP

If oChkBox.Checked = True Then

Dim oAmt2Recon As String = oMatrix.Columns.Item("120000027").Cells.Item(oRowCnt).Specific.value

'// 120000027 = Amount Column

Dim oResult As Double

                    Dim subValue() As String = oAmt2Recon.Split("MUR ")

subValue(1) = subValue(1).TrimEnd(" ")

If Not Double.TryParse(subValue(1), oResult) Then

                        'Error handling code here

End If

oCumTotal = oCumTotal + oResult

End If

            Next

       End If

replied

Hi Leon,

Nope, you code will not work if the Currency is USD or any other currency that does not contain 'R'

or contains more than 1 'R'

Use this instead.

1. Create a Function to strip the amount.

Public Function StripAmount(ByVal sInput As String) As Double

        Dim sOutPut As String = ""

        If (IsNumeric(sInput)) Then

            Return sInput

        End If

        For Each c As Char In sInput

            If (Char.IsDigit(c)) Then

                sOutPut &= c

            End If

        Next

        If sOutPut <> "" Then

            Return sOutPut

        Else

            Return 0

        End If

End Function

2. Use it like this in your code

Dim oAmt2Recon As String = oMatrix.Columns.Item("120000027").Cells.Item(oRowCnt).Specific.value

'// 120000027 = Amount Column

Dim oResult As Double = StripAmount(oAmt2Recon)


Regards

Edy



0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question