Microsoft.VisualBasic.Strings.Len() works, but Len() does not

T

Tim Daim

Can anybody please tell me what I need to do to be able to just type
Len(sMyString) instead of Microsoft.VisualBasic.Strings.Len(sMyString)

When I convert old projects (from VB6 to .NET), Len() works, but if I
create a new VB.NET project, it does not. I set up the references so
that they look exactely like my converted project (with
VisualBasic.Compatibility, etc...), but I must have missed something.

Thank you!
Tim
 
F

Family Tree Mike

Tim Daim said:
Can anybody please tell me what I need to do to be able to just type
Len(sMyString) instead of Microsoft.VisualBasic.Strings.Len(sMyString)

When I convert old projects (from VB6 to .NET), Len() works, but if I
create a new VB.NET project, it does not. I set up the references so that
they look exactely like my converted project (with
VisualBasic.Compatibility, etc...), but I must have missed something.

Thank you!
Tim


Try adding

imports Microsoft.VisualBasic.Strings

at the top of the code.
 
J

Jack Jackson

Can anybody please tell me what I need to do to be able to just type
Len(sMyString) instead of Microsoft.VisualBasic.Strings.Len(sMyString)

When I convert old projects (from VB6 to .NET), Len() works, but if I
create a new VB.NET project, it does not. I set up the references so
that they look exactely like my converted project (with
VisualBasic.Compatibility, etc...), but I must have missed something.

Thank you!
Tim

You need to import Microsoft.VisualBasic.

There are two ways to do this. The first is to add in each source
file that needs it:
Imports Microsoft.VisualBasic

The second is to go to the References section of the project's
Properties, find Microsoft.VisualBasic in the bottom listbox and check
the checkbox. This effectively adds the above Imports to each source
file. The converter probably does this.
 
K

kimiraikkonen

Can anybody please tell me what I need to do to be able to just type
Len(sMyString) instead of Microsoft.VisualBasic.Strings.Len(sMyString)

When I convert old projects (from VB6 to .NET), Len() works, but if I
create a new VB.NET project, it does not. I set up the references so
that they look exactely like my converted project (with
VisualBasic.Compatibility, etc...), but I must have missed something.

Thank you!
Tim

Just start a new Winform or Console application template.
Microsoft.VisualBasic namespace must be referenced automatically, thus
Len function will be recognized without being forced to qualify full
path.

Additional trick, when you look at "References" in Solution Explorer
by clicking "Show All Files", you may not be able to see
Microsoft.VisualBasic, but it is imported as namespace, so to confirm
this, go to project settings -> References Tab, see "imported
namespaces".

Then you can use Len function directly or String.Length property
in .NET.

Hope this helps,

Onur Güzel
 
T

Tim Daim

Thanks to all. I didn't notice that I could scroll down in the
"references" tab...
 
R

rowe_newsgroups

Can anybody please tell me what I need to do to be able to just type
Len(sMyString) instead of Microsoft.VisualBasic.Strings.Len(sMyString)

When I convert old projects (from VB6 to .NET), Len() works, but if I
create a new VB.NET project, it does not. I set up the references so
that they look exactely like my converted project (with
VisualBasic.Compatibility, etc...), but I must have missed something.

Thank you!
Tim

Above all else, I would highly recommend you drop the VB classic
syntax and programming style as you move into .NET. Not only is
thinking that .NET is the next iteration of VB classic a dangerous
assumption, but using the syntax will make it harder for you to switch
between languages (such as converting a C# sample to something usuable
in VB, or for a future job / project that is written in a different
language).

For this particular scenario, just use the .Length() property of the
string to accomplish the same thing in a cross-language friendly
fashion.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top