Using $ in some commands

D

Doogie

Hi,

I have a lot of old VB 6 experience and for the last several years
have been programming in C#. Now I'm going to be doing some VB.NET
development. As I'm "relearning" things so to speak, I remember I was
taught that using commands like Trim$ and LTrim$ instead of Trim and
LTrim were the better way to go (although I cannot remember why).

Does this still hold true in VB.NET?
 
S

Smokey Grindle

nope, there are .net oriented methods in the string class now to use
instead... if it worked in C# it will work in VB.NET basically
 
O

Oenone

Doogie said:
I remember I was
taught that using commands like Trim$ and LTrim$ instead of Trim and
LTrim were the better way to go (although I cannot remember why).

Does this still hold true in VB.NET?

No.

The reason Trim$() was preferable to Trim() was because they were both
different functions. Trim$() returned a String, Trim() returned a Variant
which was then implicitly converted to a string in your code. The Variant
approach used additional resources and was slower to execute.

In VB.NET they have tidied all of this up now, and there is a single
function called Trim() which returns a String. There's no equivalent to the
Variant-returning version of the function from VB6. If you follow the
function call with the $ suffix, this will be tolerated but ignored.

Hope that helps,
 
P

Phill W.

Doogie said:
I remember I was taught that using commands like Trim$ and LTrim$
instead of Trim and LTrim were the better way to go (although I
cannot remember why).

Trim$ returned a String.
Trim returned a Variant /containing/ a String.

There were some performance benefits in /avoiding/ the Variant "wrapper".
Does this still hold true in VB.NET?

Nope! All the String functions now return Strings and Variants are Dead
and Buried.

HTH,
Phill W.
 
H

Herfried K. Wagner [MVP]

Smokey Grindle said:
nope, there are .net oriented methods in the string class now to use
instead...

There is no reason to use the 'String' class' methods instead of the
'Strings' module's functions. These functions are still fist class citizens
in VB!
 

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