July 29, 2000

Creating help string for Enum constants

I’ve been trying to find a way to assign helpstrings for Enums in Visual Basic. The Class builder utility does that only for methods, events, and properties, but not for Enums.The IDL source code that corresponds to an Enum in a type library looks something like follws, and you can

Manually coerce to Long all Integer expressions that might overflow

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: Dim LongVariable As LongLongVariable = 256 * 256 This raises the error “Runtime Error 6, Overflow”,

Simplify your code with Inc and Dec functions

Unlike other languages – such as C and Delphi – VB lacks of the capability to increment and decrement a variable. Adding this feature, in the form of reusable Function routines, is simple: Function Inc(Value As Variant, Optional Increment As Variant = 1) As Variant Value = Value + Increment

CombSort – A very efficient algorithm

‘ Comb Sort an array of any type” CombSort is faster than all but QuickSort and close to it.’ On the other hand, the code is much simpler than QuickSort’ and can be easily customized for any array type’ This routine is based on an article appeared on the Byte’

BTree – A class for managing binary trees

Option Explicit’ Class Name : BTree’ Author : John Holfelder’ Date : 17-Apr-2000 12:08 pm’ Description : This class is a way of creating Binary search’ trees. Instead of pointers we use indexes.’ Supports adding, removing and traversing the tree.’ This is just the basic logic, file processing will be

Trimming a Vector

Suppose you create a vector and fill it with elements: vector MyVector;MyVector.reserve(20);for (int i=0 ; i tmp(MyVector);MyVector.swap(tmp); The vector temp has the same number of elements that MyVector has. By sapping it with the original vector MyVector, the capacity of MyVector changes accordingly. Consequently, MyVector’s capacity matches its size and

Use a String Object to Read Input Safely

One of the common sources for bugs and security risks is using a fixed size char array as a buffer for inputting data. For example: char buff[20];cout > buff; // what if user inserts 25 characters? The problem is that if the user enters a string that has more than

The calloc() Function

The standard C library declares the function calloc() in as follows: void *calloc(size_t elements, size_t sz); calloc() allocates space for an array of elements, each of which occupies sz bytes of storage. The space of each element is initialized to binary zeros. In other words, calloc() is similar to malloc(),

No more posts to show