473,388 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,388 developers and data experts.

What's Your Function Flavor?

ADezii
8,834 Expert 8TB
All built-in VBA Functions that deal with String handling/manipulation actually come in 2 'Flavors' such as:
Left/Left$, Right/Right$, Format/Format$, Mid/Mid$, etc.
This is a throw back to the early days of Basic, when before you could specify a Variable of a specific Data Type, programmers had to use type-specification characters rather than explicit Data Type Declarations. Some of these typical Declaration characters were '$' for String, '%' for Integer, '&' for Long Integer, '#' for Double, etc. A typical Declaration would look like:

Expand|Select|Wrap|Line Numbers
  1. Dim MyDouble#
  2. MyDouble# = 4 * Atn(1)      'Pi
  3. Debug.Print MyDouble 
This same system was applied to Function Names in that Functions ending with a '$' would return a String while its counterpart returned a Variant as in Right$ and Right. We no longer use the characters to indicate the Data Type but the Functions still remain. Left() returns a Variant and Left$() returns a String. The bottom line is that if you know you are placing the return value of a String Handling Function into a String, always use the '$' version of the Function. A simple test will demonstrate this point:

Expand|Select|Wrap|Line Numbers
  1. For i = 1 to 2000000000
  2.   strValue = Left$(strValue, 3)
  3. Next i
will take approximately 1/2 as much time as in the 2nd code snippet below because you are forcing VBA to do an extra data type conversion (Variant to String)

Expand|Select|Wrap|Line Numbers
  1. For i = 1 to 2000000000
  2.   strValue = Left(strValue, 3)
  3. Next i
In my own tests the String flavor of this particular Function ran 53% faster than the Variant flavor.
Feb 25 '07 #1
4 4942
nico5038
3,080 Expert 2GB
Interesting, but MS did announce several years ago that the "$" versions would be dropped....

Nic;o)
Feb 25 '07 #2
ADezii
8,834 Expert 8TB
Interesting, but MS did announce several years ago that the "$" versions would be dropped....

Nic;o)
Thanks Nico, I wasn't aware of that. All I know is that I still use the '$' versions to this very day. I guess they'll be dropped as soon as they do away with Macros (LOL).
Feb 26 '07 #3
NeoPa
32,556 Expert Mod 16PB
Interesting, but MS did announce several years ago that the "$" versions would be dropped....

Nic;o)
That's why I don't use them any more too.
MS are planning to drop them from the language. As you say though, it's a bit like some of their other plans like moving to ADODB from DAO etc.
I must admit that doing away with Macros won't upset me too much, but then I was warned early on that they were on their way out so I never got into them. Now, if I remember correctly, that was in the 1990s...
Feb 26 '07 #4
Killer42
8,435 Expert 8TB
I've always tended to use the $ versions, simply because I've been using them since they were the only version. Possibly also influenced by the fact that I hate variants. <Anti-variant rant removed by moderator ;)>
Mar 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
14
by: googleboy | last post by:
Hi there. I am writing a little app tha tI would like to make cross-platform (debian, RH, Fedora, Solaris, AIX, etc) Originally I decided to check what uname returned, as I didn't think it...
2
by: chunmok | last post by:
When compile using g++, following error messages appears. /usr/include/sys/sysinfo.h:101: `struct sysinfo_t sysinfo' redeclared as differe nt kind of symbol /usr/include/sys/systeminfo.h:77:...
2
by: Dan Allen | last post by:
have a lot of questions about ASP.Net. 1. What products do I need from Microsoft to develop and run ASP.NET As background, I currently use Visual InterDev to make ASP applications deployed on...
5
by: Marshall Dudley | last post by:
I have a requirement where I need to insert a cart contents into all the pages of a website. There are two websites involved, the main website of the store owner, and the website of the shopping...
6
by: Dasn | last post by:
Hi, there. 'lines' is a large list of strings each of which is seperated by '\t' I wanna split each string into a list. For speed, using map() instead of 'for' loop. 'map(str.split, lines)'...
6
by: rynato | last post by:
I am embarrassed that I cannot figure this out, as it seems fairly simple. I found a JS function I'd like to use, which animates a layer so that it moves across the screen. The problem is the...
20
by: johnnyboy7 | last post by:
I don't know a lot about ASP and I know even less about SQL. I have been trying to search the web for information to be able to get done what I need. I've tried piecing things together from many...
17
by: JohnQ | last post by:
Is that I can approximate using my ideal of a language in it. On the flip side, what I dislike most about it is all the flak/protecting-the-golden-calf one gets when using it that way. I think a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.