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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds