sx_GetRecord

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_GetRecord

VB Declaration

Declare Sub sx_GetRecord Lib "Apollo9.dll"

(cpRecord As Any)

C Declaration

VOID FAR PASCAL sx_GetRecord

(BYTEP cpRecord);

Description

Fills a defined and initialized buffer or record structure with the contents of the current record buffer.

Parameters

cpRecord: A pointer to a defined record structure (typedef) or a pre-dimensioned array of Char types. The record structure must include a delete flag field (1 character) as the first field. If using an array of Char types, ensure that enough space has been allocated for the entire record including the hidden deletion flag field.

DBF xBase data is stored in character format. Numeric fields are saved as right justified numbers. Date fields are stored as CCYYMMDD. Memo fields are ten digit numbers that refer to the relative block number of the memo in the .DBT/FPT/SMT file. The first character in the record is a delete flag ('*' if deleted, blank if not).

Data Typing Note

All fields in an xBase record are of type character and therefore all elements in a defined record type will be fixed length character strings. The extracted field elements will not be terminated with binary zeroes. Numeric fields must be converted from character to the required numeric type. Dates are stored as 'CCYYMMDD'.

Encrypted Records

If the record has been encrypted, the deletion flag in the first byte of the record will be 'D' for deleted records, and 'E' for normal non-deleted records. The record data will not be in encrypted if the correct password has been set.

Field Offsets

To retrieve field data from a record that has been read into a string, use sx_FieldOffset to set the start position of the field in the string. For example,

 

' Load control array

For i = 1 to sx_FieldCount()

cField = sx_FieldName(i)

tBox(i - 1).Text = Mid$(RecString, sx_FieldOffset(cField),

(sx_FieldWidth(cField))

Next i

VB Example

' record definition in .bas file

' log record to test sx_GetRecord/sx_PutRecord

Type LogRec

lDelFlag As String * 1 ' Note delete flag in rec definition

lCust As String * 6

lName As String * 40

lPhone As String * 20

lFax As String * 20

lLineNum As String * 2

lToWho As String * 3

lTakenBy As String * 3

lCallNum As String * 5

lCallType As String * 1

lCallTime As String * 4

lDate As String * 8

lProduct As String * 7

End Type

 

' MAIN FORM CODE

Dim lRec As LogRec

Dim iRet As Integer

 

Sub Form_Load ()

sx_CloseAll

sx_SetDateFormat ANSI

sx_SetCentury True

sx_SetDeleted True

iRet = sx_SetHandles(30)

LogArea = sx_Use("c:\vb\sxlog.dbf", "sxlog", READWRITE, SDENTX)

LogIndex1 = sx_IndexOpen("c:\vb\sxlog1.ntx")

 

sxbmain.Caption = "Version: " + sx_Version()

 

BoxSelect.Text = Format$(LogArea, "00")

BoxCount.Text = Format$(sx_RecCount(), "#####0")

BoxRecno.Text = Format$(sx_RecNo(), "###0")

 

' Get Data Record in defined structure

Call sx_GetRecord(lRec)

BoxCust.Text = lRec.lCust

BoxName.Text = lRec.lName

BoxPhone.Text = lRec.lPhone

' database info

BoxCA.Text = sx_WorkArea(0&)

BoxFN.Text = sx_BaseName()

BoxAN.Text = sx_Alias(0)

BoxLU.Text = sx_BaseDate()

BoxRS.Text = sx_RecSize()

End Sub

C Example

BYTE caString[256];

 

sx_Select(sx_WorkArea("master");

sx_GoTop();

while (!sx_Eof())

{

sx_GetRecord((BYTEP) caString);

// if rec not deleted, copy it

if (caString[0] != '*')

{

sx_Select(sx_WorkArea("copy");

sx_AppendBlank();

sx_PutRecord((BYTEP) caString);

}

sx_Select(sx_WorkArea("master");

sx_Skip(1L);

}

See Also

sx_FieldOffset, sx_PutRecord