Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

While attempting to "convert" or cast an SAPbouiCOM.Cell object into an SAPbouiCOM.Item object without success, I've come to the determination that Cells are NOT in fact "unique" objects in the UI API. My second hint to this was the fact that individual cells don't seem to have UniqueIDs. So, while they are technically "objects" in the traditional OO sense, they don't appear to fall under the category of SAPbouiCOM.Item objects, and don't seem to be able to be cast to it.

So, not being able to know what "type" of object a cell will be ahead of time, I wrote the following procedure to try to obtain some sort of value from any cell in a matrix. It's not pretty, and it's a little bit slow, and relies on error handling and try/catch blocks for situational handling... needless to say, I'm not really proud of it, but it appears to get the job done, 9 times out of 10. So here it is, if someone might find it useful someday.


''' <summary>


''' Throw an SAPbouiCOM Cell into this procedure to get its value


''' </summary>


''' <param name="oCell">A reference to the SAPbouiCOM.Cell</param>


''' <returns>A string value from the Cell</returns>


''' <remarks>On failure, will return nothing</remarks>


Private Shared Function getCellValue(ByRef oCell As SAPbouiCOM.Cell) As String


    Dim sReturnValue As String = Nothing


    Try


        'Since we don't know what type of field a Cell may be, we need to try all of the most common properties to pull data from,


        'one at a time, until we either have found one that provides data, or fail out and return nothing.


        Try


            'Try to just get the value directly as in the case of EditBoxes and ComboBoxes


            sReturnValue = oCell.Specific.Value


            If sReturnValue = "" Then


                'If the value is nothing, then try to treat it as a CheckBox/Option Button to get a value that way


                If oCell.Specific.Checked Then


                    sReturnValue = oCell.Specific.ValOn


                Else


                    sReturnValue = oCell.Specific.ValOff


                End If



                If sReturnValue = "" Then


                    'If the value is still nothing, then try a last ditch effort by using the Caption property


                    sReturnValue = oCell.Specific.Caption


                End If


            End If


            'Catch failures below as failures to cast the object as an EditText/ComboBox


        Catch ex As Exception


            'If that fails, try to treat it as a CheckBox/Option Button


            Try


                If oCell.Specific.Checked Then


                    sReturnValue = oCell.Specific.ValOn


                Else


                    sReturnValue = oCell.Specific.ValOff


                End If


            Catch ex2 As Exception


                Try


                    'If that fails, try a last ditch effort by using the Caption property


                    sReturnValue = oCell.Specific.Caption


                Catch ex3 As Exception


                    Return Nothing


                End Try


            End Try


        End Try



        'Return the ReturnValue


        Return sReturnValue



    Catch ex As Exception


        ErrorLog.AddEntryWithTrace(ex)


        Return Nothing


    End Try


End Function


Labels in this area