We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 27,397 times

Contents

Related Categories

Performance Issues - The magic $

The magic $

Many of you will have noticed that there is both a Mid and a Mid$ function, as well as Left$, Right$, and a number of other functions. However, it is not obvious what the difference actually is. When you use the Mid function, it returns a string as a Variant data type. As you would normally save the result to a string, not a Variant, Visual Basic then has to convert the Variant into a string. When you use the Mid$ function, it returns a string in a String variable. This saves Visual Basic the trouble of converting the Variant to a String, and thus increases performance. When you perform long loops of code, using Mid, and the other string functions, this can make quite a difference. I have yet to find an instance when you would actually want the Mid statement to return a Variant, and not a String, so I am not sure why Microsoft have done this. To see a list of all the procedures that have a $ (string) version as well, open the object browser (F2), enter $ into the find box, and press Find. This will give you a list of about 25 procedures where this is the case.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Once Again!

    Posted by MahR on 29 Sep 2005

    And once again a greate article by james!

  • Use of ByRef and ByVal

    Posted by JonathanEvans on 21 Mar 2002

    This posting is specifically a response to James Cowleys suggestion that using ByVal is quicker than using ByRef. This is only true when calling an out-of-process server (i.e. and ActiveX EXE). VB i...