Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
VB VB (1648) (736)
C# C# (15) (779)
ASP ASP (41)
VC++ VC++ (25)
JScript JScript (5)
» SQL Server (708)
» ORACLE (5)
» MySQL (0)
» DB2 (0)
» C/C++/ASM (11)
» Microcontroller (1)
» Circuit Design (0)
» Networking (5)
» Unix/Linux (1)
» WinNT/2k/2003 (8)
» Flash (0)
» Maya (0)
» 3D max (0)
» Photoshop (0)
» (2)
» PC Interfacing (1)
» Networking (4)
» SQL Server (4)
» VB (23)
» (4)
» VC (3)
» HTML/CSS/JavaScript (10)
» Regular Expr Tester
» Free Tools

(Page 2 of 133) 3985 Result(s) found 


The "And" operator is faster than "Mod"
Total Hit (3399) Using the "And" operator instead of "Mod" may speed up your program under certain situations. Use the And operator instead of Mod when the divisor is a number in the form 2^N. For instance, there are two methods to extract the least significant byte in an Integer: «Code LangId=1» lowByte% = valu ....Read More
Avoid Integer Overflow
Total Hit (2087) When working with integer expressions there is often the risk of raising the "Overflow" error. More specifically, there can be two occasions when this frequently occurs: When you multiply or add Integer values and the result exceeds 32,767. When you create generic string routines that iterate ....Read More
Convert Hexadecimal numbers
Total Hit (3321) While Visual Basic offers the Hex$ function that converts a decimal value into its hexadecimal equivalent number, it seems that the inverse function is missing. Not true. Try out this one-liner: «Code LangId=1» Function HexToDec(HexValue As String) As Long HexToDec = Val("&H" & HexValue) ....Read More
Counting Bits
Total Hit (2429) It seems that the only way to count the number of 1's or 0's in a binary value is creating a loop that iterates on all the 16 or 32 bits of the number. There is, however, a faster algorithm: «Code LangId=1» Function BitCount (ByVal number As Long) As Integer Dim bits As Integer, temp As Long ....Read More
Determine whether the app is running on a flawed Pentium CPU
Total Hit (2031) Here's a simple test that you can use to determine whether the application is running on a system equipped with a Pentium CPU affected by the FDIV bug: «Code LangId=1» ' return True if the CPU suffers from the FDIV bug Function IsBuggedPentium() As Boolean IsBuggedPentium = ((1 / 3221224 ....Read More
Evaluate the integer equal or higher than a given value
Total Hit (2152) The VBA language offers the Int() function, which returns the integer equal or lower than a given value, but lacks a similar function that returns the integer equal or higher than a given value. You can remedy with the following function: «Code LangId=1» ' Returns the integer equal or higher tha ....Read More
Manually coerce to Long all Integer expressions that might overflow
Total Hit (2218) This is something that expert VB developers know very well, yet every know and then an otherwise perfect VB app stops with a fatal overflow error because of Integer overflow. Consider the following code: «Code LangId=1» Dim LongVariable As Long LongVariable = 256 * 256 «/Code» This raises th ....Read More
Understanding the "Allow Unrounded Floating Point Operations" option
Total Hit (2264) The Microsoft manuals preach that all the compiler options in the Advanced Optimization dialog box are to be considered unsafe, in that they might lead to incorrect results (or just program crashes!). This is true for most of them, but often one of such options - namely, the "Allow Unrounded Floatin ....Read More
Undocumented behavior of the CInt() function
Total Hit (2415) The CInt() function rounds to the nearest integer value. In other words, CInt(2.4) returns 2, and CInt(2.6) returns 3. This function exhibits an under-documented behavior when the fractional part is equal to 0.5. In this case, this function rounds down if the integer portion of the argument is e ....Read More
Use integer division operator
Total Hit (2117) Use "\" instead of "/" when performing divisions between Integers. The "/" operator returns a Single value, therefore the seemingly efficient line «Code LangId=1» C% = A% / B% «/Code» actually requires three implicit conversions, two for converting the operands from Integer to Single (to pre ....Read More
Always use "$-typed" string functions
Total Hit (2194) VB official documentation seems to encourage you to use "$-less" string functions, e.g. Left, LTrim or UCase, instead of their time-honored Left$, LTrim$ and UCase$ counterparts. If you do so, however, you should be aware that the former ones return a variant value that, when used within string expr ....Read More
Avoid append operations with the Replace function
Total Hit (2230) I find the Replace function very useful when I want to avoid too many append operations just to insert non-printable characters. For example, the following statement: «Code LangId=1» MsgBox "Disk not ready." & vbCr & vbCr & _ "Please check that the diskette is in the drive" & vbCr & _ ....Read More
Count distinct characters in a string
Total Hit (3090) When you need to count how many occurrences of a given character are in a string, you might be tempted to go along the "traditional" Visual Basic way: «Code LangId=1» ' count spaces For i = 1 To Len(text) If Mid$(text, i, 1) = " " Then count = count + 1 Next «/Code» Ev ....Read More
Extract all quoted strings with the RegExp object
Total Hit (2945) When parsing a text file that contains quoted strings - such as a VB source file - you might want to quickly locate and extract all the quoted strings. Thanks to regular expressions and the RegExp object in the Microsoft VBScript Regular Expression type library, this task is surprisingly easy: «co ....Read More
Extract words with the RegExp object
Total Hit (3136) The following routine extracts all the words from a source string and returns a collection. Optionally, the result contains only unique words. This code is remarkably simpler than an equivalent "pure" VB solution because it takes advantage of the RegExp object in the Microsoft VBScript Regular Expr ....Read More
Faster string appending with Mid$ command
Total Hit (2551) As you probably know, the "&" operator is rather slow, especially with long strings. When you have to repeatedly append chucks of characters to the same variable, you can speed up your code using a simple trick based on the Mid$ command. The idea is that you pre-allocate a buffer long enough to acco ....Read More
Fixed-length strings allocate and deallocate faster
Total Hit (2097) Fixed-length strings are generally slower than conventional strings, because all VB string functions and operators only recognize conventional strings, thus all fixed-length strings must be transparently converted to and from conventional strings. However, arrays of fixed-length strings occupy a ....Read More
Fixed-length strings allocate and deallocate faster
Total Hit (2190) Fixed-length strings are generally slower than conventional strings, because all VB string functions and operators only recognize conventional strings, thus all fixed-length strings must be transparently converted to and from conventional strings. However, arrays of fixed-length strings occupy a ....Read More
Non obvious uses for the LIKE operator
Total Hit (2366) LIKE is probably the VB operator is most underutilized if compared to its potential. The most immediate use for this operator is to check that a string begins or ends with a given pattern. For example, it is simple to check that a Product ID is made up by a alphabetic character followed by three dig ....Read More
Process string characters using Byte arrays
Total Hit (2247) When you need to process each character in a string, you can assign the string to a byte array and iterate on its elements (remember: each Unicode character corresponds to two bytes). This approach is usually much faster because it saves a lot of Mid$ functions and, hence, a lot of temporary strings ....Read More
Replace the last occurrence of a string
Total Hit (2155) Here is a one-liner that replaces the last occurrence of a substring in a string. It is slightly less efficient than using the InstrRev plus a Replace statement, but at least you can use it in-line inside another expression. And it is also one of the few occasions to use the StrReverse function, und ....Read More
Replicate a string of any length
Total Hit (2274) The String$ function can replicate only 1-char strings, so it seems that you need a loop to duplicate strings that contain 2 or more characters. However, this is a one-liner that does the trick: «Code LangId=1» Function ReplicateString(Source As String, Times As Long) As String ' build a s ....Read More
Retrieve the currency symbol
Total Hit (2097) It is very simple to retrieve the correct currency symbol, using just plain VBA statements: «Code LangId=1» currSymbol = Trim$(Replace(FormatCurrency(0,0), "0", "")) «/Code» If you can also determine if the symbol precedes or follows the currency amount using this method: «Code LangId=1» If ....Read More
Search multiple substrings with the RegExp object
Total Hit (2964) The RegExp object in the Microsoft VBScript Regular Expression type library supports regular expression patterns containing the | (or) operator, which lets you search for multiple substrings at the same time. For example, the following piece of code lets you search for a month name in a source text: ....Read More
Swap strings the fast way
Total Hit (2636) Consider the usual way of swapping two strings: «Code LangId=1» Dim s1 As String, s2 As String Dim tmp As String ' initialize the strings s1 = String$(1000, "-") s2 = String$(1500, "+") ' do the swap, through a temporary variable tmp = s1 s1 = s2 s2 = tmp «/Code» If you put the abo ....Read More
Write concise code with the IIf function
Total Hit (1651) Use IIf when setting a value based upon an expression. This works only in situations where you have two choices, based upon the result of a Boolean expression. «Code LangId=1» 'long way If Var1 > Var2 Then Var3 = Var1 / Var2 Else Var3 = Var2 / Var1 End If 'this is more concise Var ....Read More
Write concise code with the InStr function
Total Hit (1711) You can often use the Instr function in an unorthodox way to write more concise code. A typical example is when you need to test a single character: «Code LangId=1» ' test whether CHAR contains a vowel ' the standard way If UCase$(char) = "A" Or UCase$(char) = "E" Or UCase$(char) = "I" Or UCas ....Read More
Write concise code with the Switch function
Total Hit (1264) Many VB developers don't realize that the Switch built-in function can often save a lot of code. This function takes any number of (expr, value) pairs, it evaluates all expressions and return the value related to the first expression that is found to be True. Typically you can use a Switch function ....Read More
Write concise code: a collection of simple tips
Total Hit (1761) If you fully understand how VB and VBA work, you can often save some statements. This makes your listings more concise and more readable, and indirectly optimizes your program. Here is a short list of the many tricks you can use with this goal. You don't need to initialize a numeric variable to 0 or ....Read More
A simple expression evaluator
Total Hit (2335) While any Windows user could pop up the Calculator accessory to perform any type of math calculations, it would be great if you could offer him or her the capability to do simple math from within your application. This is a very simple expression evaluator function that does it: This evaluator i ....Read More

(Page 2 of 133) 3985 Result(s) found  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ...

Recommanded Links


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.