sx_CreateField

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_CreateField

VB Declaration

Declare Sub sx_CreateField Lib "Apollo9.dll"

(ByVal cpFldName As String,

ByVal cpFldType As String,

ByVal iFldLen As Integer,

ByVal iFldDec As Integer)

C Declaration

VOID FAR PASCAL sx_CreateField

(BYTEP cpFldName,

BYTEP cpFldType,

SHORT iFldLen,

SHORT iFldDec);

Description

Defines a field to be included in a new table. A new file is created by first making a work area with sx_CreateNew (which also defines the number of fields that the table will contain). Each field is then defined with sx_CreateField, and the file is finally physically created by calling sx_CreateExec.

The number of calls to sx_CreateField must not exceed the defined number of fields passed as parameter iNumFields to function sx_CreateNew.

Parameters

cpFldName: The name of the field. Valid field names begin with a letter and may contain letters, numbers, and the underscore character. Field name maximum length is ten characters.

cpFldType: The xBase drivers allow the following types:

 C for Character

N for Numeric

D for Date

F for Float

I for Integer (strongly-typed VariField)

L for Logical

M for Memo

V for VariField

iFldLen: Field length. The maximum lengths for various types are:

 C 32733 (32k - 34)

N 19

D 3 (VariField DATE)

D 8 (CCYYMMDD)

I 4 (VariField Long Integer value, ±2 billion)

L 1

M 10 (default 10 to hold memo block reference)

V 6+ (weakly-typed value)

 

Field lengths for D, L, and M types are automatically set to 8, 1, and 10 respectively.

The maximum length of a character field that can be extracted with the sx_Get* functions is 1023. Larger fields must be extracted with sx_GetRecord. Memo and weakly-typed VariField must be extracted with sx_GetMemo.

iFldDec: The number of decimal positions if the field type is numeric. Note that the length of a numeric field that contains decimals includes the decimal point, a leading zero, and an optional sign. The minimum length for a numeric field that contains one decimal position is therefore 3 (unsigned) or 4 (signed). The maximum number of decimals allowed in DBF files is 16.

VB Example

Sub ButtonMake_Click ()

iRet = sx_CreateNew("c:\data\testnew.dbf", "test", SDEFOX, 5)

If iRet = 0 Then

MsgBox "create failed"

Else

sx_CreateField "fchar", "C", 25, 0

sx_CreateField "fnum", "N", 10, 2

sx_CreateField "flog", "L", 1, 0

sx_CreateField "fdate", "D", 8, 0

sx_CreateField "fmemo", "M", 10, 0

If sx_CreateExec() Then

MsgBox "Create succeeded"

sx_Close

Else

MsgBox "create failed"

End If

End If

End Sub

C C Example

void CNamesForm::OnInitialUpdate()

{

// do default func first

CFormView::OnInitialUpdate();  

 

// enable float support for VBXs

CVBControl::EnableVBXFloat();

 

// check if database exists

// and, if not, create  

CFileStatus status;

char* pFileName = "names.dbf";

 

// if CFile status FALSE, create new file

if (!CFile::GetStatus(pFileName, status))

{

sx_CreateNew((BYTEP) "names.dbf", (BYTEP) "name", SDENTX, 5);

sx_CreateField((BYTEP) "name", (BYTEP) "C", 30, 0);

sx_CreateField((BYTEP) "address", (BYTEP) "C", 30, 0);

sx_CreateField((BYTEP) "phone", (BYTEP) "C", 10, 0);

sx_CreateField((BYTEP) "business", (BYTEP) "C", 20, 0);

sx_CreateField((BYTEP) "createdate", (BYTEP) "D", 8, 0);

sx_CreateExec();

sx_Close();

}

}

See Also

sx_CreateNew, sx_CreateExec