4

The LA Fox Developer Newsletter
April 2000
ADO Jumpstart (Con't from page 3)


Converting a hex value to decimal in Visual FoxPro is simple.
The following code illustrate how to convert hexadecimal values
to decimal:

x = 0x00000080
?x && 128

And, if you ever need to convert back to hexadecimal:

?Transform(128,”@O”) && 0x00000080

Using our original hex value, 11101010, and working from right to
left and beginning with zero, see that the seventh bit is set.
Therefore, the seventh bit of the Attributes property, if set,
means the field is long. Going further, whatever attributes
occupy bits 1, 3, 5, and 6, also apply to this field. The following
table of field attributes should help to sort things out:

Table 4. Field Attributes


So, along with being a long field, the field is deferred,
updateable, can have a null written to it, and it may also already
contain a null value. Visually, this makes sense. How can you
do this programmatically?

If you refer to online examples(almost always programmed in
Visual Basic) you will see code like this:

If (oFieId.Attribute AND adFldLong) = adFldLong
The field is long
End If

This is pretty slick in that you can test for whether a specific
attribute bit is set by using the AND operator with the attribute
property and the constant. If you try this in Visual FoxPro, you
will get data type mismatch errors. Fortunately, there is a way.
Visual FoxPro contains a host of bit functions. One function,
BITTEST, does as its name implies. It tests whether a specified
bit in a passed argument is set. To review, we need to see if the
seventh bit in the value 234 is set. The following Visual FoxPro
code demonstrates how to use the BITTEST function:

If BitTest(234,7)
*~ The Field is long
Endif

To find out if the field is nullable:

If BltTest(234,5)
*/ The Field is long
Endif

The Attributes property of the Connection, Parameter, and
Property objects works in the same manner as illustrated
above. The differences are the names and quantity of attributes
that are present.

ADO and COM Defined Constants

ADO and OLE DB, like any COM components, make extensive
use of defined constants in the examples that document the
usage of properties, events, and methods. Other development
environments in Visual Studio such as Visual Basic and Visual
lnterdev provide lntelliSense technology, because of their
respective abilities to interact directly with the type libraries of
COM components. For these development environments, you
can reference defined constants just as if they were a part of the
native language. So, working with published examples is a fairly
trivial task. On the other hand, in the Visual FoxPro develop-
ment environment there is, in fact, a bit of a challenge. The
question always seems to be “How can I use the Visual Basic
samples in Visual FoxPro?” The biggest stumbling block is
usually in finding the value of the defined constants. In Visual
FoxPro, you need to use the #Define statement for each
constant.

One solution for obtaining the value of the ADO defined con-
stants is to obtain the MDAC SDK from Microsoft. The MDAC
SDK can be downloaded from http://www.microsoft.com/data/
mdac2.htm.

Once you install the SDK, locate the Include\ADO directory. In
that directory, you will find the ADOINT.H file, which contains all
of the enumerated types and the values for the defined con-
stants.

A second, and perhaps easier, solution is to use the resources
already installed on your machine. If you are working through
the sample code in this paper, you already have the Microsoft
Data Access Components installed on your workstation. The
Visual Basic Development Environment (both the full Visual
Basic IDE and the Visual Basic Editor in desktop applications
like Word and Excel) has a great resource called the Object
Browser. This could, in fact, be the most underutilized tool on
the planet.

To illustrate its functionality, open any desktop application that
uses Visual Basic, such as Word or Excel. Or, if you have the
Visual Basic Programming System installed, you can open that
(Con't, page 5)
Page 4

4