August 15, 1998

Avoid Deleting a Pointer More Than Once

The results of deleting an object more than once are undefined. However, if code modifications are impossible (when a third party code is used, for example), a temporary workaround to this bug is assigning a NULL value to a pointer right after it has been deleted. It is guaranteed that

Prefix Versus Postfix Operators

You can use both — and ++ as prefix and postfix operators. When applied to primitives such as int or char, they are indistinguishable in terms of efficiency. When applied to objects, on the other hand, the overloaded prefix operators are significantly more efficient than the postfix ones. Therefore, whenever

Enums Improve Readability

An enumerated type is simply a list of constants, each of which has a unique value. An Enum can improve the readability of your code by allowing you to declare a variable of your enumerated type, then assign one of the elements of the Enum to the value of the

Improve Performance by Eliminating Subexpression

Arrays can reduce the amount of code you must write to perform an operation, especially when used with a loop. By using the same array element in multiple places in your code, you can increase the speed with which your code executes if you resolve the array only once. This

Maintain Username and Password

Due to a minor bug, the Internet Transfer Control cannot use the username and password properties if they are set before the URL property. Because of this, you should always set the URL property first. This code will fail: Inet1.Password = “Chicken_Feet”Inet1.UserName = “JohnnyW”Inet1.URL = FTP://ftp.32X.comInet1.Text = Inet1.OpenURL This code,

Move a Form Without a Title Bar

Enter this code in a BAS module to let users move a window without a title bar: Declare Function ReleaseCapture Lib “user32” () As LongDeclare Function SendMessage Lib “user32” _ Alias “SendMessageA” ( _ ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any)

Simplify Variable Declarations by Using Default Types

Hungarian notation and similar naming schemes tell you at a glance the data type of any variable in your code. You know that the variable intCounter is an integer, and you know that strName is a string. You can simplify your variable declarations by telling VB that any variable you

Avoid Implicit int Declarations

The default type for missing declarations like the following is int: const k =0; //’int’ type deduced; deprecatedstatic j =5; //ditto Though still supported by the C++ standard, this convention is now considered deprecated and hence – should be avoided. Instead, explicit type names should be used: const int k

No more posts to show