Open a new project and create a procedure with four variables. Put them in a simple operation and write this operation 1000 times. Compile(1) the resulting program twice: once before and once after adding the dollar sign to the variables(2):
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = BB & CC & DD End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA$ = BB$ & CC & DD End Sub |
But, comparing the results shows that adding the dollar sign to the variables cannot change the size of applications.
Now, change A_Fistful_Of_Dollars() and pass the variables into VB6 functions. Write every function 1000 times, and compile the resulting program twice: once before and once after adding the dollar sign to the functions.
Of course, some functions remove the dollar sign:
- Abs()
- CBool()
- CByte()
- CCur()
- CDate()
- CDbl()
- CInt()
- CLng()
- CSng()
- CStr()
- Fix()
- Int()
- Len()
- InStr()
- LBound()
- StrComp()
- UBound()
And, some functions do not work with the dollar sign:
|
|
|
And, for some, using the dollar sign does not change the size of applications:
- Dir()
- FormatCurrency()
- FormatDateTime()
- FormatNumber()
- FormatPercent()
- Input()
- InputB()
- InputBox()
- MonthName()
- Replace()
- StrReverse()
- TypeName()
- WeekdayName()
But, for some:
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Chr(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Chr$(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = ChrB(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = ChrB$(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Command() End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Command$() End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = ChrW(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = ChrW$(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = CurDir(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = CurDir$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Environ(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Environ$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Error(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Error$(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Format(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Format$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Hex(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Hex$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = LCase(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = LCase$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Left(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Left$(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = LeftB(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = LeftB$(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = LTrim(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = LTrim$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Mid(BB, CC, DD) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Mid$(BB, CC, DD) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = MidB(BB, CC, DD) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = MidB$(BB, CC, DD) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Oct(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Oct$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Right(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Right$(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = RightB(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = RightB$(BB, CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = RTrim(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = RTrim$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Space(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Space$(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Str(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Str$(CC) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = String(CC, BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = String$(CC, BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Time End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Time$ End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Trim(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = Trim$(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = UCase(BB) End Sub |
Private Sub A_Fistful_Of_Dollars() Dim AA As String Dim BB As String Dim CC As Byte Dim DD As Byte 'Write it a thousand times AA = UCase$(BB) End Sub |
Using the dollar sign changes the size of applications(3):
Function | Size (Bytes) | Bytes Used | Function$ | Size (Bytes) | Bytes Used | Reduce Rate |
---|---|---|---|---|---|---|
Chr() | 49152 | 65536 | Chr$() | 28672 | 32768 | 41.6% |
ChrB() | 49152 | 65536 | ChrB$() | 28672 | 32768 | 41.6% |
ChrW() | 57344 | 65536 | ChrW$() | 32768 | 32768 | 42.8% |
Command() | 45050 | 65536 | Command$() | 24576 | 32768 | 45.4% |
CurDir() | 61440 | 65536 | CurDir$() | 40960 | 65536 | 33.3% |
Environ() | 61440 | 65536 | Environ$() | 40960 | 65536 | 33.3% |
Error() | 61440 | 65536 | Error$() | 40960 | 65536 | 33.3% |
Format() | 94208 | 98304 | Format$() | 69632 | 98304 | 26.0% |
Hex() | 61440 | 65536 | Hex$() | 40960 | 65536 | 33.3% |
LCase() | 61440 | 65536 | LCase$() | 28672 | 32768 | 53.3% |
Left() | 65536 | 65536 | Left$() | 32768 | 32768 | 50% |
LeftB() | 65536 | 65536 | LeftB$() | 32768 | 32768 | 50% |
LTrim() | 61440 | 65536 | LTrim$() | 28672 | 32768 | 53.3% |
Mid() | 81920 | 98304 | Mid$() | 45065 | 65536 | 44.9% |
MidB() | 81920 | 98304 | MidB$() | 45065 | 65536 | 44.9% |
Oct() | 61440 | 65536 | Oct$() | 40960 | 65536 | 33.3% |
Right() | 65536 | 65536 | Right$() | 32768 | 32768 | 50% |
RightB() | 65536 | 65536 | RightB$() | 32768 | 32768 | 50% |
RTrim() | 61440 | 65536 | RTrim$() | 28672 | 32768 | 53.3% |
Space() | 49152 | 65536 | Space$() | 32768 | 32768 | 33.3% |
Str() | 61440 | 65536 | Str$() | 40960 | 65536 | 33.3% |
String() | 65536 | 65536 | String$() | 40960 | 65536 | 37.5% |
Time | 45056 | 65536 | Time$ | 24576 | 32768 | 45.4% |
Trim() | 61440 | 65536 | Trim$() | 28672 | 32768 | 53.3% |
UCase() | 61440 | 65536 | UCase$() | 28672 | 32768 | 53.3% |
So, in Visual Basic 6.0:
- Adding the dollar sign ($) to some functions reduces the size of applications.
- The reduce rate can reach to upwards of 50%.
Footnotes
1. Compiling Options
Project Menu - Project Properties - Compile - Compile to Native Code - Optimize for Fast Code
2. Of course, just to the strings, because:
The dollar sign ($) type-declaration character represents a String in Visual Basic.
See String data type.
3. See also
In Visual Basic 6.0, some functions have two versions, one that returns a String value and one that returns a Variant value. These function pairs are differentiated by a dollar sign ($) suffix for the String version; for example, Chr and Chr$.
See String ($) Function for Visual Basic 6.0 Users.
And:
Some of the VBA string functions come in two varieties, one that returns a string, and one that returns a string-type Variant value. The names of the functions that return a string include a dollar sign ("$"); for example, Chr$, Format$, LCase$, Left$, LTrim$, Mid$, Right$, RTrim$, Space$, Trim$, and UCase$. The functions that return a string-type Variant value have no dollar sign; for example, Chr, Format, LCase, Left, LTrim, Mid, Right, RTrim, Space, Trim, and UCase. The string-returning functions are faster.