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

3

39

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

like this:

Replace$("EG000000", "0", "")
Oophorectomy answered 1/12, 2011 at 12:38 Comment(0)
S
48

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...

Scarfskin answered 1/12, 2011 at 12:41 Comment(3)
For the sake of completeness, the MSDN Link.Afterdamp
What you are referencing is Type Characters, which make dim s$ and dim s as string the same. See Heinzi's answer.Horseshoes
Not correct. Heinzi's explanation is the correct one.Lombard
S
30

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.

Spitzer answered 1/12, 2011 at 13:5 Comment(1)
plus one for the VBA reference.Rosabella
H
6

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", "")
Horseshoes answered 1/12, 2011 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.