Click here to Skip to main content
16,011,805 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I created this function to remove vbCrLf from the values of properties in a Custom Class:(vTransaction)

Public Function ValidateTransaction(ByRef vTransaction)            Dim property1 As String
        Dim value1 As String

        For Each p As System.Reflection.PropertyInfo In vTransaction.GetType().GetProperties()
            If p.CanRead Then
                property1 = p.Name '// FOR TESTING to identify Property Name
                value1 = p.GetValue(vTransaction, Nothing)
                If (TypeOf value1 Is String) Then
                    If value1 <> " " And value1 <> "" Then
                        'MsgBox("Before .Replace:" & vbNewLine & value1.ToString) '// FOR TESTING.
                        value1 = value1.ToString.Replace(vbCrLf, " ")
                        'MsgBox("After .Replace:" & vbNewLine & value1.ToString) '// FOR TESTING.
                    End If
                End If
            End If
        Next

        Return vTransaction

    End Function


Throughout testing I can verify that vbCrLf is being replaced with a space as expected. When I re-examine vTransaction the changes have not been retained and the vbCrlf's are still there.
What do I need to do to retain the changes being made to values in vTransaction.
Posted

You got it, you changed it. Now put it back, i.e. SetValue.

Alan.
 
Share this answer
 
Comments
gspeedtech 10-Jun-11 18:06pm    
Thanks
Sergey Alexandrovich Kryukov 10-Jun-11 20:04pm    
Simple as that, a 5.
--SA
That fixed it:

VB
Public Function ValidateTransaction(ByRef vTransaction)
    Dim property1 As Object
    Dim value1 As Object

    For Each p As System.Reflection.PropertyInfo In vTransaction.GetType().GetProperties()
        If p.CanRead Then
            property1 = p.Name '// FOR TESTING to identify Property Name
            value1 = p.GetValue(vTransaction, Nothing)
            If (TypeOf value1 Is String) Then
                If value1 <> " " And value1 <> "" Then
                    'MsgBox("Before .Replace:" & vbNewLine & value1.ToString) '// FOR TESTING.
             p.SetValue(sTransaction, value1 = value1.ToString.Replace(vbCrLf, " "), Nothing)
                    'MsgBox("After .Replace:" & vbNewLine & value1.ToString) '// FOR TESTING.
                End If
            End If
        End If
    Next

    Return sTransaction

End Function
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jun-11 20:05pm    
Sure, a 5.
--SA
Your code doesn't really make any sense. But, what you did was get a copy of a string value, remove all the vbCrLf's from the copy, then drop it and not do anything with it. You returned only the value that was passed into the method, so yeah, nothing changed.
 
Share this answer
 
Comments
gspeedtech 10-Jun-11 18:07pm    
Thanks
Sergey Alexandrovich Kryukov 10-Jun-11 20:04pm    
That's the thing, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900