String parts - not a question for a change

S

StrandElectric

Now trying Google before trying for solutions here. Given up completely on
the useless help system in 2008Express. Half the searches give nothing. What
a slack product! Google has alwsays been fine so far.

Here's a curly one. I wanted to separate the 3 bytes of a 3 byte string
(reading a legacy file). In vb6 it was Left$(String,1), Mid$(String,1,1),
Right$(String,1).

vb.net is of course sans the $ but...For some peculiar reason in vb.net you
have to say Microsoft.VisualBasic.Left(String,1) and
Microsoft.VisualBasic.Right(String, 1) BUT the syntax for Mid is similar
(less the $) as vb6 with no 'Microsoft.VisualBasic'! How's that for
inconsistency?
 
R

Robert Roland

For some peculiar reason in vb.net you
have to say Microsoft.VisualBasic.Left(String,1)

There are many ways to skin a cat. In dotnet, a string is an object
with built-in methods and properties. Here's how I like to do it for
"Left" and "Mid":

s = "test123"
t = s.Substring(1, 1)

For "Right", it becomes a little ugly:

t = s.Substring(s.Length - 1, s.Length)
 
C

Cor

Strand,

What you tell could be normal for VB phone development, but I assume you are
not doing that.

The import to the Microsoft.VisualBasic namespace should be standard
available.

Can you try a brand new project to see if you have maybe by accident deleted
that default namespace.

After that we can help you to solve that again.

Be aware that you can (not must) use also the Net substring command

dim x = aString.Substring(0, 10) (the most 10 left positions in a string
which is at least 10 characters long)

Cor

"StrandElectric" wrote in message
Now trying Google before trying for solutions here. Given up completely on
the useless help system in 2008Express. Half the searches give nothing. What
a slack product! Google has alwsays been fine so far.

Here's a curly one. I wanted to separate the 3 bytes of a 3 byte string
(reading a legacy file). In vb6 it was Left$(String,1), Mid$(String,1,1),
Right$(String,1).

vb.net is of course sans the $ but...For some peculiar reason in vb.net you
have to say Microsoft.VisualBasic.Left(String,1) and
Microsoft.VisualBasic.Right(String, 1) BUT the syntax for Mid is similar
(less the $) as vb6 with no 'Microsoft.VisualBasic'! How's that for
inconsistency?
 
A

Andrew Morton

StrandElectric said:
vb.net is of course sans the $ but...For some peculiar reason in
vb.net you have to say Microsoft.VisualBasic.Left(String,1) and
Microsoft.VisualBasic.Right(String, 1) BUT the syntax for Mid is
similar (less the $) as vb6 with no 'Microsoft.VisualBasic'! How's
that for inconsistency?

You can use "Imports VB=Microsoft.VisualBasic" so that you can abbreviate
them to VB.Left and VB.Right. There is a collision with the names of a
form's Left and Right properties, and the form properties win.
 
A

Armin Zingler

Am 14.01.2011 12:27, schrieb Robert Roland:
There are many ways to skin a cat. In dotnet, a string is an object
with built-in methods and properties. Here's how I like to do it for
"Left" and "Mid":

s = "test123"
t = s.Substring(1, 1)

For "Right", it becomes a little ugly:

t = s.Substring(s.Length - 1, s.Length)

Mr. Strand, be aware that the String methods are zero-based, i.e.
the first character has index zero (in opposite to the old
VB6 methods which are 1-based).

I also recommend using the String methods instead of the old
VB6 methods because the latter ones only call the former ones,
therefore, the old ones would be a detour.

I'm afraid, there's no "Right" function in the String class - you
have the talent to stumble on the few downsides. :)
 
C

Cor

Andrew,

That should not be needed in VB Express, even my sentence about phone was
not valid because that cannot be used with VB Express.

It is possible to remove, add that namespace by:

Project -> Application Properties -> References and then check or uncheck at
imported namespaces Microsoft.Visual Basic.

Because that Strand has been busy with references, I can assume he has
unchecked that by accident because it is set by default if you create a new
project in VB Express.

I asked him to try to get a shorter explanation route.

:)

Cor


"Andrew Morton" wrote in message
vb.net is of course sans the $ but...For some peculiar reason in
vb.net you have to say Microsoft.VisualBasic.Left(String,1) and
Microsoft.VisualBasic.Right(String, 1) BUT the syntax for Mid is
similar (less the $) as vb6 with no 'Microsoft.VisualBasic'! How's
that for inconsistency?

You can use "Imports VB=Microsoft.VisualBasic" so that you can abbreviate
them to VB.Left and VB.Right. There is a collision with the names of a
form's Left and Right properties, and the form properties win.
 

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