B. Clay Shannon B. Clay Shannon - 10 days ago 6
Vb.net Question

Why am I getting 'Trim' is not declared with this VB.NET code?

I am trying to get a VB.NET app to compile. Besides the "elephant in the room", I'm also getting 7 "'Trim' is not declared" errors on code like this:

enter image description here

...as well as one "'IsNothing' is not declared. It may be inaccessible due to its protection level." on this line:

If IsNothing(memberList) = False Then


I don't know VB, so there may be a simple solution to this, but I have no clue what the problems are.

Answer

The Trim function requires a reference to Microsoft.VisualBasic from the assembly Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Usually is preferable to use the native Trim method from the string class and not add a reference to this assembly (mainly used to help porting old VB6 apps)

mail.CC.Add(addr.Trim())

Notice also that the string.Trim removes other whitespace characters as tabs while the Microsoft.VisualBasic function does not.