Find index key

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 6.5


Find index key (indexedField; value) Longint

ParameterTypeDescription
indexedFieldFieldIndexed field on which to execute the search
valueField | VariableValue to search
Value found
Function resultLongintNumber of the record found or
-1 if no record was found

Description

The Find index key command returns the number of the first record whose indexedField field is equal to value.

If no records are found, Find index key returns -1.

After calling this command, value contains the value found. This feature allows you to execute searches using the wildcard character ("@") on Alpha fields and then retrieve the value found.

This command doesn't modify the current selection or the current record.

This command is fast because it only uses the index, and is particularly useful to avoid creating double entries during data entry.

Example

In an audio CD database, during data entry let's assume that you want to verify the singer's name to see if it already exists in the database. Because homonyms can exist, you don't want the [Singer]Name field to be unique. Therefore, in the input form, you can write the following code in the [Singer]Name field's object method:

   If (Form event=On Data Change)
      $RecNum:=Find index key([Singer]Name;[Singer]Name)
      If ($RecNum # -1)  ` If this name has already been entered
         CONFIRM("A singer with the same already exists. Do you want to see the record?";"Yes";"No")
         If (OK=1)
            GOTO RECORD([Singer];$RecNum) 
         End if
      End if
   End if

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next