Help on CUSTOM INDEX

Help on CUSTOM INDEX

Postby MaxP » Mon Oct 14, 2013 3:45 pm

Hi,

I have a problem with building a custom index.
For example: I have a database with 4 character-fields (
Name1, Name2, Name3, Name4, ...) .and. I want to have every name in my
custom index.

Code: Select all  Expand view

#include "Fivewin.ch"

FUNCTION MAIN()
        LOCAL   aStr := { { "NAME1", "C", 10, 0 }, ;
                          { "NAME2", "C", 10, 0 }, ;
                          { "NAME3", "C", 10, 0 }, ;
                          { "NAME4", "C", 10, 0 } }

        FERASE( "TEST.DBF" )
        FERASE( "TEST.DBT" )
        FERASE( "TEST.NTX" )

        DBCREATE( "TEST.DBF", aStr )

        USE TEST

        INDEX ON NAME1 TO TEST CUSTOM        // Create a CUSTOM INDEX

        APPEND BLANK
        REPLACE NAME1 WITH "First"
        REPLACE NAME2 WITH "First2"
        REPLACE NAME3 WITH "First3"
        REPLACE NAME4 WITH "First4"

        APPEND BLANK
        REPLACE NAME1 WITH "Second"
        REPLACE NAME2 WITH "Second2"
        REPLACE NAME3 WITH "Second3"
        REPLACE NAME4 WITH "Second4"

        APPEND BLANK
        REPLACE NAME1 WITH "Third"
        REPLACE NAME2 WITH "Third2"
        REPLACE NAME3 WITH "Third3"
        REPLACE NAME4 WITH "Third4"

        USE

        USE TEST INDEX TEST

        GO 2
       
        ORDKEYADD()                          // Add default KEY field NAME1

        ORDKEYADD( ,, TEST->NAME2 )          // Add KEY for field NAME2


        IF DBSEEK( "Second    " )
                Msgstop( "Second: FIND" )
        ELSE
                Msgstop( "Second: NOT FIND" )
        ENDIF

        IF DBSEEK( "Second2   " )
                Msgstop( "Second2: FIND" )
        ELSE
                Msgstop( "Second2: NOT FIND" )
        ENDIF


        USE
RETURN NIL
 


The first ORDKEYADD() will work fine, but the following 3 ORDKEYADD()
only will add the Name1 to the index. I will never get Name2, Name3
oder Name4 in my custom index. Whats going wrong??

thanks
Massimo
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm

Re: Help on CUSTOM INDEX

Postby MarcoBoschi » Mon Oct 14, 2013 4:15 pm

Because "Second2" does not exist in field name1 in any records

NAME1 NAME2 NAME3 NAME4
First First2 First3 First4
Second Second2 Second3 Second4
Third Third2 Third3 Third4

Is it correct?
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Help on CUSTOM INDEX

Postby MaxP » Mon Oct 14, 2013 4:22 pm

Yes,

but I want to add the value of the field Name2 on CUSTOM INDEX
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm

Re: Help on CUSTOM INDEX

Postby Antonio Linares » Mon Oct 14, 2013 10:17 pm

Max,

Using DBFCDX and specifying the first param in OrdKeyAdd() seems to work fine:

Code: Select all  Expand view
#include "Fivewin.ch"

request DBFCDX

FUNCTION MAIN()
        LOCAL   aStr := { { "NAME1", "C", 10, 0 }, ;
                          { "NAME2", "C", 10, 0 }, ;
                          { "NAME3", "C", 10, 0 }, ;
                          { "NAME4", "C", 10, 0 } }
        FERASE( "TEST.DBF" )
        FERASE( "TEST.DBT" )
        FERASE( "TEST.NTX" )

        DBCREATE( "TEST.DBF", aStr )

        USE TEST VIA "DBFCDX"

        INDEX ON Field->NAME1 TO TEST CUSTOM        // Create a CUSTOM INDEX

        APPEND BLANK
        REPLACE NAME1 WITH "First"
        REPLACE NAME2 WITH "First2"
        REPLACE NAME3 WITH "First3"
        REPLACE NAME4 WITH "First4"

        APPEND BLANK
        REPLACE NAME1 WITH "Second"
        REPLACE NAME2 WITH "Second2"
        REPLACE NAME3 WITH "Second3"
        REPLACE NAME4 WITH "Second4"

        APPEND BLANK
        REPLACE NAME1 WITH "Third"
        REPLACE NAME2 WITH "Third2"
        REPLACE NAME3 WITH "Third3"
        REPLACE NAME4 WITH "Third4"

        USE

        USE TEST VIA "DBFCDX" // INDEX TEST

        GO 2
       
        MsgInfo( ORDKEYADD( 1 ) )                         // Add default KEY field NAME1

        MsgInfo( ORDKEYADD( 1 ,, TEST->NAME2 ) )          // Add KEY for field NAME2

        DbSetorder( 1 )
       
        IF DBSEEK( "Second    " )
                Msgstop( "Second: FIND" )
        ELSE
                Msgstop( "Second: NOT FIND" )
        ENDIF

        IF DBSEEK( "Second2" )
                Msgstop( "Second2: FIND" )
        ELSE
                Msgstop( "Second2: NOT FIND" )
        ENDIF

        USE
RETURN NIL
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Help on CUSTOM INDEX

Postby Antonio Linares » Mon Oct 14, 2013 10:21 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Help on CUSTOM INDEX

Postby MaxP » Tue Oct 15, 2013 5:42 am

many thanks Antonio

Massimo
User avatar
MaxP
 
Posts: 84
Joined: Thu Jul 12, 2007 2:02 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests