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.
You are not setting the property value again. You are just creating a string that is not used after that. Your innermost If-block should be something like this: