May 9, 2002

Set the Cursor for Your Components

All AWT component classes have a setCursor() method that allows for dynamically setting the cursor for a particular component and any subcomponents.For example, if you set the cursor for a Panel, all the components added to that Panel will inherit the Panel’s cursor unless the components explicitly override it. Once

Creating and Using Thread-Scoped Variables

Sometimes you need variables scoped by thread so that each thread has an independent copy. There’s an easy way to create and manage such variables.The java.lang.ThreadLocal class provides a wrapper around an object that’s guaranteed to be independent in each accessing thread. To create a ThreadLocal object, implement the initialValue()

Use Forward Declarations to Speed Up Compiling

If class B uses only pointers or references of class A, you don’t have to include A.h. You can simply forward declare class A as shown below. //File B.hclass A; //forward Decalarationclass B{ A * ptrA; .. //other members};

An Easy Way to Check Boolean System Properties

Suppose you want to pass a Boolean system property, -DDEBUG=true or -DDEBUG=false, from the command line. Normally, you’d probably use the following in source code to retrieve it: boolean b = Boolean.valueOf(System.getProperty(“DEBUG”)).booleanValue();if(b) { //do something;}or just treat it as a string system property:if(System.getProperty(“DEBUG”).equalsIgnoreCase(“true”)) { //do something;} The following code offers

A Quick Way To Initialize All the Members of a Struct To 0

// Quickly zero out a struct. This can be applied// To an array of structs also, since// memset() initializes memory regions#include struct sample {int a;short int b;int c;};struct sample s;// Initialize all members to zero (Be careful of// Incompatible Data types.memset( s, 0, sizeof(sample) );// Array of structs examplememset( s,

Scope of Variables Declared in for()

The new ANSI C++ standard specifies that variables declared as in for(int i=1; …) have a scope local to the for statement. Unfortunately, older compilers (like Visual C++ 5.0) use the older concept that the scope is the enclosing group. Below, I list two possible problems arising from this change

Sorting Part of a Field

Use the following code: select *,right(field1,4) as Col1 from [Tablename]order by col1 You can do it by using substring: SELECT *, substring(field1, 3, 5) as col1from [tablename]order by col1

Open Textfile Data as a Recordset Using ADODB

‘*********************************************************************’Text files Reading’You can use Microsoft Text Driver’*********************************************************************Public Function Read_Text_File() As ADODB.Recordset Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Dim conn As ADODB.Connection Set conn = New ADODB.Connection conn.Open “DRIVER={Microsoft Text Driver (*.txt; *.csv)};” & _ “DBQ=” & App.Path & “;”, “”, “” rs.Open “select * from [test#txt]”,