AutoFill in Text Box

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: AutoFill in Text Box

Post by Rathinagiri »

When pressing back space, it selects left character in stead of deleting it.
Yes. In your previous code, what was the behavior? Left character gets deleted and nothing is selected in the right?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: AutoFill in Text Box

Post by esgici »

Hi All

In appearance this isn't easy task as far as seen at first sight.

Please look and test this version.

Code: Select all

/*
  

  AutoFill in Text Box try

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

#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' ;
      MAIN 
      
      ON KEY UP     ACTION AutoFill( ThisWindow.Name, "txbCountry",  aCountries, 1 )
      ON KEY DOWN   ACTION AutoFill( ThisWindow.Name, "txbCountry",  aCountries, 2 )
      
      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 )
      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 )        
 
   *!!!!!!!!!!!!!!!!!!!!!!!!
   *
   * I don't like this low-level trick ! :( 
   *
   SendMessage( GetControlHandle( cTxBname, cFrmName), 177, LEN( cValue ), nPosit )

RETU // AF_Apply()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
I'm waiting your comments.

PS: Please attention: Sometimes seems nothing changed by seeing text box value not changed. This occurs especially after pressing backspace or delete keys. This is because the result off filling process become identical with previous one.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: AutoFill in Text Box

Post by Rathinagiri »

Hi Esgici,

Had u tested my last version here?

IMHO, we can't have a generic UP/DOWN key definitions because, if you define another listbox in this window, you can't scroll that listbox with the UP/DOWN key.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: AutoFill in Text Box

Post by esgici »

Hi Rathi

Yes, tested.

IMHO at this stage adequate working of auto filling process is more important than scope of up-down keys. For localizing instead of global on-key definition will be easy by your method, I thought.

Thanks and regards.

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: AutoFill in Text Box

Post by Rathinagiri »

As you had rightly said, working of the process is more important.

Had you gone through the back space handling too?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: AutoFill in Text Box

Post by esgici »

rathinagiri wrote: Had you gone through the back space handling too?
Didn't you tried ?

Any problem ?

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: AutoFill in Text Box

Post by esgici »

Hi

IMHO that love-level trick

Code: Select all

SendMessage( GetControlHandle(  ...
is causing some serious problems.

Please extract ( or simply comment ) it in my last code.

It's very last line :

Code: Select all

   SendMessage( GetControlHandle( cTxBname, cFrmName), 177, LEN( cValue ), nPosit )
Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: AutoFill in Text Box

Post by Rathinagiri »

Yes. Now it is working perfect. Thanks a lot Esgici.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: AutoFill in Text Box

Post by sudip »

Hi Rathi and Esgici,

Thank you very much. Now, everything is fine :) I tested it :D

Yesterday I was busy with formatting my laptop. It's registry was corrupted. And at that time I couldn't understand low level functions. Still now I am very novice in HMG. ;)

Rathi, sorry my friend. I was wrong regarding user interface. I have to learn many things from you :D

With best regards.

Sudip
With best regards,
Sudip
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: AutoFill in Text Box

Post by sudip »

rathinagiri wrote:
When pressing back space, it selects left character in stead of deleting it.
Yes. In your previous code, what was the behavior? Left character gets deleted and nothing is selected in the right?
Yes, my friend, it was not currect :)

Regards.

Sudip
With best regards,
Sudip
Post Reply