locked
Explicit Conversion from UDT(User Defined Type) to String type RRS feed

  • Question

  • User1729205220 posted

    Following is my code.

    Private Structure DISPLAY_ELEMENT_TYPE
            Dim lCodeID As Integer
            Dim lCodeTypeID As Integer
            Dim sDescription As String
            Dim bRemoved As Boolean
            Dim lRowNum As Integer
        End Structure

    Private DispElem() As DISPLAY_ELEMENT_TYPE

    Private Sub Swap(ByRef i As Integer, ByRef j As Integer)
            Dim temp As DISPLAY_ELEMENT_TYPE
            Dim iRow As Integer
            Dim jRow As Integer
            iRow = DispElem(i).lRowNum
            jRow = DispElem(j).lRowNum
            temp = LSet(DispElem(i))
            DispElem(i) = LSet(DispElem(j))
            LSet(DispElem(j)) = temp
            DispElem(i).lRowNum = iRow
            DispElem(j).lRowNum = jRow
     End Sub

    Actually this is vb6 to .net converted code. I m getting compile error at following line

    temp = Lset(DispElem(i)) bcz Lset is not supported in .Net

    Lset accept string data type for first parameter and interger for second.

    If you know any alternet solution or if you have any source code for Explicit convert UDT to string type and vice versa.

    Any advice will be helpful for me.

    Thursday, July 22, 2010 3:07 PM

Answers

  • User-660870441 posted

    Hi,

    Lset() method is used to clone objects. It’s not the same as Padright() method. So I suggest you implementing ICloneable interface to achieve it. I made sample code for you. Please have a try on it.

    ' Update this structure
    Structure DISPLAY_ELEMENT_TYPE
        Implements ICloneable
        Private lCodeID As Integer
        Private lCodeTypeID As Integer
        Private sDescription As String
        Private bRemoved As Boolean
        Private lRowNum As Integer
    
        ' A new method to clone object
        Public Function Clone() As Object
            Dim another As New DISPLAY_ELEMENT_TYPE()
            another.lCodeID = lCodeID
            another.lCodeTypeID = lCodeTypeID
            another.sDescription = sDescription
            another.bRemoved = bRemoved
            another.lRowNum = lRowNum
            Return another
        End Function
    End Structure
    
    Private DispElem() As DISPLAY_ELEMENT_TYPE
    
    Private Sub Swap(ByRef i As Integer, ByRef j As Integer)
        Dim temp As DISPLAY_ELEMENT_TYPE
        Dim iRow As Integer
        Dim jRow As Integer
        iRow = DispElem(i).lRowNum
        jRow = DispElem(j).lRowNum
    
        ' Update codes here
        temp = DirectCast(DispElem(i).Clone(), DISPLAY_ELEMENT_TYPE)
        DispElem(i) = DirectCast(DispElem(j).Clone(), DISPLAY_ELEMENT_TYPE)
        DispElem(j) = DirectCast(temp.Clone(), DISPLAY_ELEMENT_TYPE)
    
        DispElem(i).lRowNum = iRow
        DispElem(j).lRowNum = jRow
    End Sub

    If I misunderstood you, please feel free to let me know.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 27, 2010 4:29 AM

All replies

  • User-366246501 posted

    I think you want to covert string value to Integer and viceVersa.

    Please gothrough these links:-

    http://wiki.answers.com/Q/How_do_you_convert_string_to_integer_in_VBNet

    http://wiki.answers.com/Q/How_do_you_Convert_integer_to_string_in_vb_net

    http://vbnotebookfor.net/2007/09/14/comparing-string-to-integer-conversion-methods-in-vbnet/



    Thursday, July 22, 2010 5:42 PM
  • User1729205220 posted

    No I want to convert User Defined Type to String type. So i can use Padright method of string class that equivalant Lset methind in vb6

    The problem is Padright method accept parameter as string but my objcet is UDT type.

    Please advice some more alternative solution.

    Friday, July 23, 2010 9:12 AM
  • User-660870441 posted

    Hi,

    Lset() method is used to clone objects. It’s not the same as Padright() method. So I suggest you implementing ICloneable interface to achieve it. I made sample code for you. Please have a try on it.

    ' Update this structure
    Structure DISPLAY_ELEMENT_TYPE
        Implements ICloneable
        Private lCodeID As Integer
        Private lCodeTypeID As Integer
        Private sDescription As String
        Private bRemoved As Boolean
        Private lRowNum As Integer
    
        ' A new method to clone object
        Public Function Clone() As Object
            Dim another As New DISPLAY_ELEMENT_TYPE()
            another.lCodeID = lCodeID
            another.lCodeTypeID = lCodeTypeID
            another.sDescription = sDescription
            another.bRemoved = bRemoved
            another.lRowNum = lRowNum
            Return another
        End Function
    End Structure
    
    Private DispElem() As DISPLAY_ELEMENT_TYPE
    
    Private Sub Swap(ByRef i As Integer, ByRef j As Integer)
        Dim temp As DISPLAY_ELEMENT_TYPE
        Dim iRow As Integer
        Dim jRow As Integer
        iRow = DispElem(i).lRowNum
        jRow = DispElem(j).lRowNum
    
        ' Update codes here
        temp = DirectCast(DispElem(i).Clone(), DISPLAY_ELEMENT_TYPE)
        DispElem(i) = DirectCast(DispElem(j).Clone(), DISPLAY_ELEMENT_TYPE)
        DispElem(j) = DirectCast(temp.Clone(), DISPLAY_ELEMENT_TYPE)
    
        DispElem(i).lRowNum = iRow
        DispElem(j).lRowNum = jRow
    End Sub

    If I misunderstood you, please feel free to let me know.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 27, 2010 4:29 AM
  • User1729205220 posted

    Thanks you so much for help and support

    Tuesday, July 27, 2010 9:55 AM