1

I just found the below line of code in a project I am working on. I have never seen functions with the $

I found online that it is a vb string function. The page said the "Right$" is more efficient than simply writing "Right"

So is this still current with the most up to date vb language features or is it deprecated?

Right$(sNumToBeFormatted, 8)
masteroleary
  • 1,014
  • 2
  • 16
  • 33
  • Would you mind sharing that page with us? – Visual Vincent Apr 11 '16 at 16:52
  • I just tried it, and the compiler recognizes both, however, I would try opt for a more "pure .NET" way of doing it using the methods in the string class. In classic VB, using the dollar sign was more efficient, because it cast the result to string, rather than Variant, if my memory serves correctly. Since Variants don't exist in VB.NET, there is no reason to use it. – Jeremy Apr 11 '16 at 16:53
  • This question has some alternatives to use. http://stackoverflow.com/questions/2813505/get-last-5-characters-in-a-string – Jeremy Apr 11 '16 at 16:58
  • 1
    IMHO, `Microsoft.VisualBasic.Right` is as likely to stay in VB.NET as, say, `If...Then...`. There is no exact equivalent of the former in the .NET framework. – Andrew Morton Apr 11 '16 at 17:21
  • Everything in `Microsoft.VisualBasic` is valid, current and supported. This is not necessarily true for `Microsoft.VisualBasic.Compatibility`, please do not confuse the two. – GSerg Apr 11 '16 at 17:25

2 Answers2

1

$ sign means that returned value of Right will be string

You can also do this

Dim someString$

which is equivalent to

Dim someString as String

For more go here

As to this question

So is this still current with the most up to date vb language features or is it deprecated?

There is nothing stopping you from using it as it is supported, but because it is not popular at all it shouldn't be so next person reading code wont be going over it like you are at the moment.

This syntax was already optional in vb6.

Claudius
  • 1,883
  • 2
  • 21
  • 34
1

I found online that it is a vb string function. The page said the "Right$" is more efficient than simply writing "Right"

VB6 had (and VBA still has) two versions of many string functions.
One version accepted and returned Strings, another one accepted and returned Variants. The string versions had $ in their name to make them stand out.

One cannot say that using Right$ is always better than using Right. It depends on the type of your source and result data.
If you receive data as Variants and send it out as Variants, like e.g. Excel does, using Right will result in fewer conversions between String and Variant.
If your data is originally a String, using Right$ is better.

So is this still current with the most up to date vb language features or is it deprecated?

VB.NET only includes the typed versions, but it does not show the $ anymore.

So Right$ is the up to date version, but it was renamed to simply Right. There is no choice anymore.

There is still choice in VBA, where both versions are valid and supported.

GSerg
  • 76,472
  • 17
  • 159
  • 346