what is the meaning of the dollar sign after a method name in vb.net

18,407

Solution 1

Old type notifier - see this

Some other old ones:

& -> Long
% -> Integer
# -> Double
! -> Single
@ -> Decimal
$ -> String

Still exist in VB.Net for the sake of backward compatibility...

Solution 2

In "classic" VB, there were two versions of the built in-string functions. Let me use Left as an example:

  • Left(s, length) takes a variant as the first parameter and returns a variant.
  • Left$(s, length) takes a string as the first parameter and returns a string.

This distinction still exists in modern-day VBA.

I suspect that the reason behind this is that strings in VBA cannot be Null (note that Null <> ""). Thus, when dealing with nullable database fields, you had to use variant variables. Variant variables can take any value, including all of the integral values (strings, integers, ...) as well as some special values such as Null, Empty or Missing. The non-$ functions allowed you to use variants as input and get variants as output. For example, Left(Null, ...) returns Null.

In VB.NET, this distinction is no longer necessary: The non-$ functions do exactly the same as the $ functions, which are kept only for backwards compatibility with old code.

Solution 3

What Heinzi said and to clear up the type character business

    Dim s$ = "FooBar" 'dim s as String = "FooBar"

    Dim r As String
    Stop

    r = Replace$(s, "Bar", "")
    '.Net equivalent
    r = s.Replace("Bar", "")
Share:
18,407
user288916
Author by

user288916

Updated on June 19, 2022

Comments

  • user288916
    user288916 about 2 years

    what is the meaning of the dollar sign after a method name in vb.net

    like this:

    Replace$("EG000000", "0", "")