Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- RLIB 3.0a Reference - <b>function:</b> ntxkeyval() http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Function:    NTXKEYVAL()

Purpose:     Get the controlling index key value of the current record

Syntax:      NTXKEYVAL()

Arguments:   None

Returns:     The value of the current database record index key, of a type
             determined by the type of field in the index key expression.

Description: This function allows you to easily get the value of an index
             key field from the currently selected database.  It is handy
             in place of using the INDEXKEY() function and subsequent
             macro substitution.

Notes:       If no database file is open, or no index file is open,
             NTXKEYVAL() returns a null string ("").

             NTXKEYVAL() returns the value of the index key expression,
             not the index expression string.  It is used to evaluate the
             index key for the current record of the currently selected
             database.  Retrieving the value of the index key field is
             useful if you have applications that list records on the
             screen.

             For instance, while using PICKREC(), you may want to instruct
             PICKREC() to refresh the screen if, after a record was
             edited, the value of a field used as part of the controlling
             index expression was changed.  This is because changing such
             a record causes the order of the database to appear
             different.  NTXKEYVAL() can be used to retrieve the value of
             the key field before and after the edit.  If changed,
             PICKREC() can be instructed to repaint the screen with a
             <row> value of -1.

Example:     *-- index a database with a 12 character long Name field
             *-- and a 6 character serial number field
             INDEX ON Name+Serialnum TO myindex
             SEEK "Low"
             ? INDEXKEY()            && returns "Name+Serialnum"
             ? INDEXKEYVAL()         && returns "Low         12345 "

             *------------------------------------------------------------
             *-- test if and index key field was changed during an edit
             *-- save the index key value for comparison
             savekey = NTXKEYVAL()
             @ x,y GET keyfield
             READ
             *-- see if an index key field was changed in the process
             IF savekey != NTXKEYVAL()
                *-- do corrective things
             ENDIF


             *------------------------------------------------------------
             mrow = 0
             DO WHILE .T.
                FPROMPT(".-+=Edit,Ins=Insert,Del=Delete,Esc=Exit")
                mrow =PICKREC(1,0,20,79,"CUSTOMER->Name","","",mrow,.F.,1)
                DO CASE
                CASE LASTKEY() = 27             && Escape
                   EXIT

                CASE LASTKEY() = 22             && Insert
                   newrec = .T.

                CASE ( BOF() .OR.  EOF() )      && a record must exist
                   LOOP

                CASE LASTKEY() = 13             && Enter
                   savekey = NTXKEYVAL()        && save current key value
                   DO EditRoutine
                   IF savekey != NTXKEYVAL()    && did it change
                      mrow = -1                 && refill box from top
                   ENDIF

                CASE LASTKEY() = 7              && Delete key
                   BLIP()
                   IF BOXASK("Delete record? (Y/N) ")="Y"
                      IF .NOT.  NO_RLOCK()
                         DELETE
                         UNLOCK
                         mrow = 0               && force PICKREC() refresh
                      ENDIF
                   ENDIF
                   LOOP

                OTHERWISE                       && trap other exits
                   LOOP

                ENDCASE
             ENDDO


Source:      RL_NTXKE.PRG

See also:    PICKREC()

See Also: PICKREC()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson