Can $ Reduce the Size of VB6 Applications?

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:

  • Asc()
  • Array()
  • Atn()
  • Choose()
  • Cos()
  • CreateObject()
  • DateAdd()
  • DateDiff()
  • DatePart()
  • DateSerial()
  • DateValue()
  • Day()
  • Exp()
  • FileLen()
  • Filter()
  • GetObject()
  • Hour()
  • InStrRev()
  • IsArray()
  • IsDate()
  • IsEmpty()
  • IsNull()
  • IsNumeric()
  • IsObject()
  • Log()
  • Minute()
  • Month()
  • MsgBox()
  • Now()
  • RGB()
  • Rnd()
  • Round()
  • Second()
  • Sgn()
  • Sin()
  • Split()
  • Sqr()
  • Tan()
  • Timer()
  • TimeSerial()
  • TimeValue()
  • VarType()
  • Weekday()
  • Year()

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:

  1. Adding the dollar sign ($) to some functions reduces the size of applications.
  2. 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.

See Returning Portions of a String.



Comments

  • Re. Can $ Reduce the Size of VB6 Applications?

    Posted by SanganakSakha on 01/29/2007 07:20am

    Homaioon, Very very interesting articles! I immensely like such articles that go beyond the commands and reveal unusual insights. One questions I have is b How do I remember which functions remove the $ sign, which ones do not work with it, which ones do not benefit and the ones that do benefit. There are two alternatives b find the logic behind it. If you can do so that would be wonderful. If such logic is difficult to find then test each and every function and create a ready recknor. It would be very time consuming. But it could be done collaboratively. If you agree to co-ordinate, I could test 10 functions that you assign to me and let you know their classification. Others can similarly contribute and webll have the ready recnor ready within a few days. Let me know how it goes. - Sanjay Kulkarni, - Pune, India.

    • Response

      Posted by visual master on 02/01/2007 08:23am

      Dear Sanjay Kulkarni! We don't understand the logic behind these functions, because we have not made them. And, what has been important to me is to find the functions that can reduce the size of VB6 applications, because I think the other functions have not unknown important effects on them. Thank you, Homaioon Eslami.

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds