July 17, 1999

Cross-midnight time measurements

Any time the behavior of your code depends on the Timer function you should take into account the (more or less) remote possibility that your code is executed just before midnight. Take for example the following code: Sub Pause(seconds as Single) Dim initTime as Single initTime = Timer Do: Loop

Check a GUID

The following routine quickly check that a string contains a valid GUID. Of course, it doesn’t check that the GUID refers to a valid entity, but at least it lets you quickly reject invalid values: Function CheckGUID(Value As String) As Boolean Const PatternGUID = “{########-####-####-####-############}” CheckGUID = UCase$(Value) Like Replace(PatternGUID,

A VarPtr substitute function for VB4

Both VB5 and VB6 include a hidden function, named VarPtr, that returns the address of a variable. Many advanced tricks and routines, on VB2TheMax or other site, use this function. However, VB4 doesn’t directly support VarPtr, so it seems that you can’t use such routines with those older versions of

How to View the Source of External JS Files

You can use an external JS file to store modular JavaScript code. In addition to being modular, it hides your JavaScript code from novice users. However, it is possible for any user to see the source code contained in any JS file. Just use this syntax in either the address

Get a Hold of Swing Defaults

Swing is one of the best things that happened to Java GUI developers. At the heart of Swing is the javax.swing.UIManager class (com.sun.java.swing.UIManager for Swing 1.03 and below) that keeps track of the current look and feel and its defaults at three levels: user defaults, look and feel defaults, and

Use Stored Procedures in Place of Embedded SQL

Stored procedures offer many advantages over dynamic SQL, including improved performance and scalability. The SQL code in a stored procedure is parsed and normalized when you create it. Stored procedures are optimized and saved in native machine language. When a stored procedure is called, it’s all ready to go. When

Do Not Use Operator New in a Throw Statement

Dynamic allocation of an exception (as in this example) is not a good idea: class Err{public: Err(const char * description);};void f(){ if (disaster) throw new Err(“failed”); //exception object is dynamically allocated on the free store //

One More Reason to Avoid Macros

Even macros that look harmless can have detrimental effects. For example: #define twice(x) ((x)+(x)) The macro, twice, is well parenthesized and performs a simple addition operation. Despite its simplicity, there can still be problems. When twice takes an expression with side effects as an argument, it yields unexpected results: int

No more posts to show