Page 3 of 4

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 10:58 am
by esgici
Hi

Thanks my friends Rathi and Sudip :D ; but sorry, IMO neither working perfect nor everything is fine :(

Because from user perspective there are some confusing situations: under some conditions back space and delete keys seems not working :(

Anyway here is new version localized UP and DOWN arrow keys by using Rathi's method.

Code: Select all

/*
  

  AutoFill in Text Box try

  Started by Esgici
  
  Enhanced by Roberto Lopez and Rathinagiri
  
  2009.05.10
  
*/

#include "minigui.ch"


PROC Main()

   aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
   
   ASORT( aCountries )                    // This Array MUST be sorted
       
   DEFINE WINDOW frmAFTest ;
      AT 0,0 ;
      WIDTH  550 ;
      HEIGHT 300 ;
      TITLE 'AutoFill in Text Box try (BE2)' ;
      MAIN 
      
      ON KEY ESCAPE ACTION frmAFTest.Release
      
      DEFINE LABEL lblCountry
         ROW        50
         COL        50
         VALUE      "Country :"
         RIGHTALIGN .T.
         AUTOSIZE   .T.
      END LABEL // lblCountry
            
      DEFINE TEXTBOX txbCountry 
         ROW         48
         COL         110
         ONCHANGE    AutoFill( ThisWindow.Name, This.Name, aCountries )
         ONGOTFOCUS  AFKeySet( ThisWindow.Name, This.Name, aCountries )
         ONLOSTFOCUS AFKeyRls( ThisWindow.Name )
      END TEXTBOX // txbCountry   
         
   END WINDOW // frmAFTest
   
   frmAFTest.Center
   
   frmAFTest.Activate

      
RETU // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC AutoFill( ;              // Auto filling text box
                cFrmName  ,;  // Form / Windows name 
                cTxBName  ,;  // Text Box Name 
                aList,;       // Items list 
                nCaller )     // NIL : OnChange, 1: UP, 2: Down
               
   STATIC cLastVal := '',;
          n1Result := 0
   
   LOCAL  cTxBValue := GetProperty( cFrmName, cTxBName, "Value" ),;     // Text Box Value 
          nCarePos  := GetProperty( cFrmName, cTxBName, "CaretPos" ),;  // Text Box CaretPos
          cCurval   := ''
          
      
   IF HB_ISNIL( nCaller )

      IF !( cLastVal == cTxBValue )    
      
         cCurval  := LEFT( cTxBValue, nCarePos )
         
         IF !EMPTY( cCurval ) 
         
            n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} ) 
            
            IF n1Result > 0
               cCurval := aList[ n1Result ]
            ENDIF n1Result > 0
            
         ENDIF !EMPTY( cCurval ) 
         
         cLastVal := cCurval  
         
         AF_Apply( cFrmName, cTxBName, cCurval, nCarePos )     
         
      ENDIF cLastVal # cCurval      
      
   ELSE 
   
      IF n1Result > 0
      
         IF nCaller < 2 
            n1Result -= IF( n1Result > 1, 1, 0 )
         ELSE
            n1Result += IF( n1Result < LEN( aList ), 1, 0 )
         ENDIF   
             
         cCurval := aList[ n1Result ]
               
         cLastVal := cCurval  
         
         AF_Apply( cFrmName, cTxBName, cCurval, nCarePos )     
         
      ENDIF n1Result > 0
      
   ENDIF HB_ISNIL( nCaller )
                            
RETU // AutoFill()   
   
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC AF_Apply( ;
               cFrmName,;
               cTxBName,; 
               cValue,;
               nPosit ) 

   SetProperty( cFrmName, cTxBName, "Value", cValue )        
   SetProperty( cFrmName, cTxBName, "CaretPos", nPosit )        
 
RETU // AF_Apply()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC AFKeySet(;
               cFrmName ,; 
               cTxBName ,;
               aitems )
               
   ON KEY UP   OF &cFrmName  ACTION AutoFill( cFrmName, cTxBName, aitems, 1 )
   ON KEY DOWN OF &cFrmName  ACTION AutoFill( cFrmName, cTxBName, aitems, 2 )

RETU // AFKeySet()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROC AFKeyRls( ;
               cFrmName ) 
               
   RELEASE KEY UP   OF &cFrmName 
   RELEASE KEY DOWN OF &cFrmName 

RETU // AFKeyRls()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
One comforting point is : it's usable for indulgent users :)

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 1:05 pm
by Rathinagiri
Now, it is working fine, I think.

IMHO, we can remove the parameters windowname and controlname as suggested by Roberto.

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 3:03 pm
by esgici
rathinagiri wrote:Now, it is working fine, I think.

IMHO, we can remove the parameters windowname and controlname as suggested by Roberto.
Hi Rathi

Unfortunately I couldn't understand Roberto's codes :(

Please could you apply ?

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 3:19 pm
by Rathinagiri
Yep. Here it is.

Code: Select all

    /*
     

      AutoFill in Text Box try

      Started by Esgici
     
      Enhanced by Roberto Lopez and Rathinagiri
     
      2009.05.10
     
    */

    #include "minigui.ch"


    PROC Main()

       aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
       
       ASORT( aCountries )                    // This Array MUST be sorted
           
       DEFINE WINDOW frmAFTest ;
          AT 0,0 ;
          WIDTH  550 ;
          HEIGHT 300 ;
          TITLE 'AutoFill in Text Box try (BE2)' ;
          MAIN
         
          ON KEY ESCAPE ACTION frmAFTest.Release
         
          DEFINE LABEL lblCountry
             ROW        50
             COL        50
             VALUE      "Country :"
             RIGHTALIGN .T.
             AUTOSIZE   .T.
          END LABEL // lblCountry
               
          DEFINE TEXTBOX txbCountry
             ROW         48
             COL         110
             ONCHANGE    AutoFill( aCountries )
             ONGOTFOCUS  AFKeySet( aCountries )
             ONLOSTFOCUS AFKeyRls(  )
          END TEXTBOX // txbCountry   
             
       END WINDOW // frmAFTest
       
       frmAFTest.Center
       
       frmAFTest.Activate

         
    RETU // Main()

    *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

    PROC AutoFill( ;              // Auto filling text box
                    aList,;       // Items list
                    nCaller )     // NIL : OnChange, 1: UP, 2: Down
                   
       STATIC cLastVal := '',;
              n1Result := 0
       
       LOCAL  cFrmName := thiswindow.name,;
              cTxBname := this.name,;
              cTxBValue := GetProperty( cFrmName, cTxBName, "Value" ),;     // Text Box Value
              nCarePos  := GetProperty( cFrmName, cTxBName, "CaretPos" ),;  // Text Box CaretPos
              cCurval   := ''

         
       IF HB_ISNIL( nCaller )

          IF !( cLastVal == cTxBValue )   
         
             cCurval  := LEFT( cTxBValue, nCarePos )
             
             IF !EMPTY( cCurval )
             
                n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} )
               
                IF n1Result > 0
                   cCurval := aList[ n1Result ]
                ENDIF n1Result > 0
               
             ENDIF !EMPTY( cCurval )
             
             cLastVal := cCurval 
             
             AF_Apply( cCurval, nCarePos )     
             
          ENDIF cLastVal # cCurval     
         
       ELSE
       
          IF n1Result > 0
         
             IF nCaller < 2
                n1Result -= IF( n1Result > 1, 1, 0 )
             ELSE
                n1Result += IF( n1Result < LEN( aList ), 1, 0 )
             ENDIF   
                 
             cCurval := aList[ n1Result ]
                   
             cLastVal := cCurval 
             
             AF_Apply( cCurval, nCarePos )     
             
          ENDIF n1Result > 0
         
       ENDIF HB_ISNIL( nCaller )
                               
    RETU // AutoFill()   
       
    *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

    PROC AF_Apply( ;
                   cValue,;
                   nPosit )
       Local cFrmName := thiswindow.name,;
             cTxBName := this.name

       SetProperty( cFrmName, cTxBName, "Value", cValue )       
       SetProperty( cFrmName, cTxBName, "CaretPos", nPosit )       

    RETU // AF_Apply()

    *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

    PROC AFKeySet(;
                   aitems )
       Local cFrmName := thiswindow.name,;
             cTxBName := this.name
                   
       ON KEY UP   OF &cFrmName  ACTION AutoFill( cFrmName, cTxBName, aitems, 1 )
       ON KEY DOWN OF &cFrmName  ACTION AutoFill( cFrmName, cTxBName, aitems, 2 )

    RETU // AFKeySet()

    *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

    PROC AFKeyRls( )
       Local cFrmName := thiswindow.name
                   
       RELEASE KEY UP   OF &cFrmName
       RELEASE KEY DOWN OF &cFrmName

    RETU // AFKeyRls()

    *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.



Re: AutoFill in Text Box

Posted: Sun May 10, 2009 3:24 pm
by esgici
rathinagiri wrote:Yep. Here it is.
Without using _HMG_SYSDATA ?

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 4:35 pm
by esgici
rathinagiri wrote:Yep. Here it is.
Sorry, but :

Error: Harbour MiniGUI 2.9.0 (2009.05.03)
Control: Of frmAFTest Not defined. Program Terminated
Called from GETPROPERTY(6793)
Called from AUTOFILL(70)
Called from (b)AFKEYSET(138)
Called from _DOCONTROLEVENTPROCEDURE(4680)
Called from EVENTS(553)
Called from _DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(4322)
Called from DOMETHOD(7224)
Called from MAIN(52)

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Sun May 10, 2009 5:13 pm
by Rathinagiri
Sorry for the bug.

Please try now.

Code: Select all


        /*
         

          AutoFill in Text Box try

          Started by Esgici
         
          Enhanced by Roberto Lopez and Rathinagiri
         
          2009.05.10
         
*/        #include "minigui.ch"


        PROC Main()

           aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ),   CRLF )
           
           ASORT( aCountries )                    // This Array MUST be sorted
               
           DEFINE WINDOW frmAFTest ;
              AT 0,0 ;
              WIDTH  550 ;
              HEIGHT 300 ;
              TITLE 'AutoFill in Text Box try (BE2)' ;
              MAIN
             
              ON KEY ESCAPE ACTION frmAFTest.Release
             
              DEFINE LABEL lblCountry
                 ROW        50
                 COL        50
                 VALUE      "Country :"
                 RIGHTALIGN .T.
                 AUTOSIZE   .T.
              END LABEL // lblCountry
                   
              DEFINE TEXTBOX txbCountry
                 ROW         48
                 COL         110
                 ONCHANGE    AutoFill( aCountries )
                 ONGOTFOCUS  AFKeySet( aCountries )
                 ONLOSTFOCUS AFKeyRls(  )
              END TEXTBOX // txbCountry   
                 
           END WINDOW // frmAFTest
           
           frmAFTest.Center
           
           frmAFTest.Activate

             
        RETU // Main()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

        PROC AutoFill( ;              // Auto filling text box
                        aList,;       // Items list
                        nCaller,;     // NIL : OnChange, 1: UP, 2: Down
                        cControlName )
                        
           STATIC cLastVal := '',;
                  n1Result := 0
           
           LOCAL  cFrmName := '',;
                  cTxBname := '',;
                  cTxBValue := '',;     // Text Box Value
                  nCarePos  := 0,;  // Text Box CaretPos
                  cCurval   := ''

           cFrmName := thiswindow.name
           if pcount() == 3
              cTxBName := cControlName
           else
              cTxBName := this.name
           endif
           cTxBValue := GetProperty( cFrmName, cTxBName, "Value" )     // Text Box Value
           nCarePos  := GetProperty( cFrmName, cTxBName, "CaretPos" )  // Text Box CaretPos
             
           IF HB_ISNIL( nCaller )

              IF !( cLastVal == cTxBValue )   
             
                 cCurval  := LEFT( cTxBValue, nCarePos )
                 
                 IF !EMPTY( cCurval )
                 
                    n1Result := ASCAN( aList, { | c1 | UPPER( LEFT( c1, LEN( cCurval ) ) ) == UPPER( cCurval )} )
                   
                    IF n1Result > 0
                       cCurval := aList[ n1Result ]
                    ENDIF n1Result > 0
                   
                 ENDIF !EMPTY( cCurval )
                 
                 cLastVal := cCurval
                 
                 AF_Apply( cFrmName,cTxBName,cCurval, nCarePos )     
                 
              ENDIF cLastVal # cCurval     
             
           ELSE
           
              IF n1Result > 0
             
                 IF nCaller < 2
                    n1Result -= IF( n1Result > 1, 1, 0 )
                 ELSE
                    n1Result += IF( n1Result < LEN( aList ), 1, 0 )
                 ENDIF   
                     
                 cCurval := aList[ n1Result ]
                       
                 cLastVal := cCurval
                 
                 AF_Apply( cFrmName,cTxBName,cCurval, nCarePos )     
                 
              ENDIF n1Result > 0
             
           ENDIF HB_ISNIL( nCaller )
                                   
        RETU // AutoFill()   
           
        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

        PROC AF_Apply( ;
                       cFrmName,;
                       cTxBName,; 
                       cValue,;
                       nPosit )

           SetProperty( cFrmName, cTxBName, "Value", cValue )       
           SetProperty( cFrmName, cTxBName, "CaretPos", nPosit )       

        RETU // AF_Apply()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

        PROC AFKeySet(;
                       aitems )
           Local cFrmName := thiswindow.name,;
                 cTxBName := this.name
                       
           ON KEY UP   OF &cFrmName  ACTION AutoFill(  aitems, 1,cTxBName )
           ON KEY DOWN OF &cFrmName  ACTION AutoFill(  aitems, 2,cTxBName )

        RETU // AFKeySet()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

        PROC AFKeyRls( )
           Local cFrmName := thiswindow.name
                       
           RELEASE KEY UP   OF &cFrmName
           RELEASE KEY DOWN OF &cFrmName

        RETU // AFKeyRls()

        *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.




Re: AutoFill in Text Box

Posted: Sun May 10, 2009 5:37 pm
by esgici
That's all :D

Thanks a lot :)

Regards

--

Esgici

Re: AutoFill in Text Box

Posted: Mon May 11, 2009 5:50 pm
by Vanguarda
Hi Esgici,

thanks for sharing this function... it is very amazing. will help me a lot

I also thank all the brother for help in advancing this function.

Thanks a lot,

I´m glad for participe this community.

Regards,

Re: AutoFill in Text Box

Posted: Mon May 11, 2009 5:58 pm
by esgici
Hola Vanguarda
Vanguarda wrote: thanks for sharing this function... it is very amazing. will help me a lot
No thank required, everything is for community,

Viva HMG, viva Roberto :!: :D

Regards

--

Esgici