What is the difference between Command $ and Command in VB 6?

What is the difference between Command $ and Command in VB 6?

MsgBox Command$ MsgBox Command 
+6
arguments vb6
source share
2 answers

Each time you see $ after a function in VB 6, this means that the function is a String version , i.e. it returns a value of type String . The unsigned version is a Variant function, which of course means that it returns a value of type Variant .

In general, you should always use String versions in Variant versions.


The dollar sign also means the same thing if it appears after the variable name instead of the specified type. Here it is part of a larger family of abbreviated "type declaration characters" that were needed in earlier versions of BASIC, but by the time even VB 6 arrived on the scene, it was obsolete. For example:

 Dim name$ 

indicates a variable named name that is of type String . Alternative (and preferred!) Notation:

 Dim name As String 

If you are dealing with legacy code where they appear, here is the entire list for completeness:

 & Long % Integer # Double ! Single @ Decimal $ String 
+17
source share

Both of them return the same string, but the command returns the string in Variant.

In fact, there are quite a few VB functions that do this. The $ at the end indicates that the function returns a string, while copies return variants.

+5
source share

All Articles