5.3.2 Populating a List with the Contents of a Table
To populate a list with the contents of a table, you must first request the set of records you want to use and then receive them. *RECEIVEIMMED mode is used for better performance. In this example, LceSetSelectOptions is used to set the select mode.
LceDeleteSelect can be used to clear any previously select results. This is required if a previous Select is interrupted and is not fully received.
After the file and fields in it have been selected with LceRequestSelect, a LceReceiveNextX loop is used to retrieve all selected records.
The following example is a simplified version of the code in the SetSkillsList subroutine in SIMPLE.VBP.
' reads all skill descriptions and populates the skill list
On Error Resume Next
' remove any previous query results
iRet = LceDeleteSelect(iSession, "SKLTAB")
'----------------------------------------
' Set Select to IMMEDIATE MODE as recommended for reasons of speed
iRet = LceSetSelectOptions(iSession, "*RECEIVEIMMED")
'----------------------------------------------------
' Select fields and file from which records will be retrieved
iRet = LceRequestSelect(iSession, "SKILDESC", "SKLTAB", "", False)
'-----------------------------------------------------
sBuff = String(FIELD_DATA_SIZE, Chr(0)) ' Initialize buffer
lstSkills.Clear 'Clear List
'-----------------------------------------------------------------
'Read all records selected
While (LceReceiveNextX(iSession, sBuff, FIELD_DATA_SIZE, fldData(0), 1) = LceTrue)
'-----------------------------------------------------------------
If (fldData(i).flags = 0) Then
' Value is not SQLNULL
lstSkills.AddItem sTrim(sBuff) ' add description to list
End If
Wend
Notes:
All the records have to be retrieved, otherwise you must use LceDeleteSelect before you use any of the other record manipulation functions.
While not used in this case, (in this example the whole table is required) the number of retrieved records can be restricted by specifying keys in LceRequestSelect. The key values are set with LceSetFieldValue. A variation of LceRequestSelect, LceRequestSelectWhere, allows the specification of an additional SQL WHERE-like condition.
Instead of using a buffer to receive the data, LceGetFieldValueX could be used. The buffer in LceReceiveNextX is then not required.
While (LceReceiveNextX(iSession,"", 0, vbNullString, 0) = LceTrue)
'------------------------------------------------
iRet = LceGetFieldValueX(iSession, "SKILDESC", sBuff, lFlags)
lstSkills.AddItem sTrim(sBuff)
Wend