Choose Compares Carefully

Choose Compares Carefully

A straight ASCII compare, such as ‘F “A” < "B"THEN' is much faster then using VB's StrComp("A", "B",1). However, when you use this test to sort an array of strings, your resultwill not be "internationally" correct. Using an ASCII comparesimply tests the string for which the ASCII values of one character comebefore those of another. The StrComp() function uses the current code pagesetting in Windows to determine which characters alphabetize before othersbased on the current country setting. Using the StrComp() when sortingand displaying output to your user will make your application much moreinternationally friendly. If you are sorting and testing for internal purposes, an ASCII compareis much faster. Make sure you are consistent with the compares or yourresults might not be what you expect. Don't do a binary chop against analphabetized array using an ASCII compare or vice versa. On the same note, using UCase$() (or LCase$()) is very fast. However,these functions only zip through a string, setting or clearing the fifthbit of characters "A-Z," "a-z." To adjust case properlyfor international character sets, use StrConv(string$, vbUpperCase|vbLowerCase).Once again, for your own code's internal use, use UCase$()/LCase$() becausethey are faster, but for display purposes use StrConv(). During testing of UCase$() .versus StrConv(), both returned the sameresults under VB4. However, since StrConv() provides other services youmay need (or in case this was simply a Microsoft bug), you should stilluse StrConv() in place of UCase$()/LCase$().

See also  11 Effective Keyword Research Tools and Techniques

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist