3

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.

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 3
    Why don't you use the NET version of Trim? The one that is part of string class? addr.Trim() – Steve Nov 30 '16 at 21:38
  • 3
    You might not have the `Microsoft.VisualBasic` namespace included. That might be the case since it also chokes on `IsNothing`. The cool kids use the NET counterparts – Ňɏssa Pøngjǣrdenlarp Nov 30 '16 at 21:40

4 Answers4

3

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.

Steve
  • 213,761
  • 22
  • 232
  • 286
1

You have to use addr.Trim instead of Trim(addr)

Read more about Trim in this MSDN article

And you should use

If not memberList Is Nothing Then

Instead of

If IsNothing(memberList) = False Then

Or

You have to import Microsoft.VisualBasic namespace

Hadi
  • 36,233
  • 13
  • 65
  • 124
1

If you use the Left(), Mid(), and Right() string functions you might find it easier to convert those too:

Left(t, l) becomes t.Substring(0, l)

Mid(t, s, l) becomes t.Substring(s-1, l)

Right(t, l) becomes t.Substring(t.Length - l)

Often Left and Right are properties and stop you using the old VB string functions.

SSS
  • 4,807
  • 1
  • 23
  • 44
0

String.Trim doesn't take a string parameter. It returns a new string in which all leading and trailing occurrences of a set of specified characters from the current String object are removed.

It should be...

 addr.Trim()
Trevor
  • 7,777
  • 6
  • 31
  • 50