Uppercase in textbox (HMG4)

Moderator: Rathinagiri

Post Reply
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Uppercase in textbox (HMG4)

Post by pctoledo »

Hi Friends, how to convert characters to uppercase in textbox?
Regards/Saludos,

Toledo

Clipper On Line
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Uppercase in textbox (HMG4)

Post by pctoledo »

Friends, to decide the problem with CaseConvert and MaxLength, I modified the file textbox.prg:

// Internal Data

Code: Select all

   DATA nMaxLength                                INIT   0

Code: Select all

METHOD MaxLength( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nMaxLength := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD CASEConvert( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nCaseConvert := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD ProcessTextChange( cText ) CLASS TEXTBOX
   LOCAL icp, InBufferLeft, InBufferRight

   HB_SYMBOL_UNUSED( cText )

   IF ::lDateTextBoxActive
      ::lDateTextBoxActive := .F.
   ELSE
      icp := ::oQTObject:cursorPosition()
      IF ::nCaseConvert>0
       cText := IF(::nCaseConvert==1,UPPER(cText),LOWER(cText))
       ::oQTObject:setText( cText )
       ::oQTObject:setCursorPosition( icp )
      ENDIF
      IF ::nMaxLength>0
         IF Len( cText ) > ::nMaxLength
            InBufferLeft := Left( cText , icp )
            InBufferRight := Right( cText , Len( cText ) - icp - 1 )
            ::oQTObject:setText( LEFT(InBufferLeft + InBufferRight,::nMaxLength) )
            ::oQTObject:setCursorPosition( icp )
         ENDIF
      ENDIF
      IF Len( ::cInputMask ) > 0
         IF ::cTextBoxType == 'MASKEDTEXT'
            IF ::lMaskedFlag == .T.
               Self:ProcessCharmask( .t. )
             ENDIF
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ELSEIF ::cTextBoxType == 'CHARMASKTEXT'
            Self:ProcessCharMask()
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ENDIF

      ELSE

         IF ::cTextBoxType == 'NUMTEXT'
            Self:ProcessNumText()
         ENDIF
         IF ValType( ::bOnChange ) != 'U'
            Eval( ::bOnChange )
         ENDIF
      ENDIF

   ENDIF

RETURN NIL
I do not know if it is the best solution, but it gave certain!

Samples:

Code: Select all

      With Object oFriend := TextBox():New( "oFriend" )
         :Row            := 85
         :Col            := 15
         :Width          := 485
         :Height         := 20
         :ToolTip        := 'Name of the Friend'
         :MaxLength      := 50
         :OnEnter        := { || InsertTab() }
         :CaseConvert    := 1
      End With
Regards/Saludos,

Toledo

Clipper On Line
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Uppercase in textbox (HMG4)

Post by pctoledo »

It gives error with accented letters (ÁÉÃÕÇ) :oops: :cry:
Regards/Saludos,

Toledo

Clipper On Line
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Uppercase in textbox (HMG4)

Post by pctoledo »

Hi Friends, problem resolved:

Code: Select all

METHOD ProcessTextChange( cText ) CLASS TEXTBOX
   LOCAL icp, InBufferLeft, InBufferRight, InBuffer

   HB_SYMBOL_UNUSED( cText )

   IF ::lDateTextBoxActive
      ::lDateTextBoxActive := .F.
   ELSE
      icp := ::oQTObject:cursorPosition()
      IF ::nCaseConvert>0
       InBuffer := ::oQTObject:text()
       InBuffer := IF(::nCaseConvert==1,UPPER(InBuffer),LOWER(InBuffer))
       ::oQTObject:setText( InBuffer )
       ::oQTObject:setCursorPosition( icp )
      ENDIF
      IF ::nMaxLength>0
         InBuffer := ::oQTObject:text()
         IF Len( InBuffer ) > ::nMaxLength
            InBufferLeft := Left( InBuffer , icp )
            InBufferRight := Right( InBuffer , Len( InBuffer ) - icp - 1 )
            ::oQTObject:setText( LEFT(InBufferLeft + InBufferRight,::nMaxLength) )
            ::oQTObject:setCursorPosition( icp )
         ENDIF
      ENDIF
      IF Len( ::cInputMask ) > 0
         IF ::cTextBoxType == 'MASKEDTEXT'
            IF ::lMaskedFlag == .T.
               Self:ProcessCharmask( .t. )
             ENDIF
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ELSEIF ::cTextBoxType == 'CHARMASKTEXT'
            Self:ProcessCharMask()
            IF ValType( ::bOnChange ) != 'U'
               Eval( ::bOnChange )
            ENDIF
         ENDIF

      ELSE

         IF ::cTextBoxType == 'NUMTEXT'
            Self:ProcessNumText()
         ENDIF
         IF ValType( ::bOnChange ) != 'U'
            Eval( ::bOnChange )
         ENDIF
      ENDIF

   ENDIF

RETURN NIL
Regards/Saludos,

Toledo

Clipper On Line
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: Uppercase in textbox (HMG4)

Post by Rathinagiri »

Nice work
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Uppercase in textbox (HMG4)

Post by mrduck »

Code: Select all

METHOD MaxLength( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nMaxLength := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD CASEConvert( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nValue
   ELSEIF PCOUNT() == 1
      ::nCaseConvert := nValue
   ENDIF

   RETURN NIL

Sorry, but this code has an error in the RETURN ::nValue...
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Uppercase in textbox (HMG4)

Post by pctoledo »

Correct, it is true:

Code: Select all

METHOD CASEConvert( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nCaseConvert
   ELSEIF PCOUNT() == 1
      ::nCaseConvert := nValue
   ENDIF

   RETURN NIL

Code: Select all

METHOD MaxLength( nValue ) CLASS TEXTBOX

   IF PCOUNT() == 0
      RETURN ::nMaxLength
   ELSEIF PCOUNT() == 1
      ::nMaxLength := nValue
   ENDIF

   RETURN NIL
Sorry!
Regards/Saludos,

Toledo

Clipper On Line
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Uppercase in textbox (HMG4)

Post by mrduck »

Patch commited to svn

please check
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Uppercase in textbox (HMG4)

Post by pctoledo »

mrduck, need only change:

Code: Select all

   DATA nMaxLength                                INIT   0
Thanks!
Regards/Saludos,

Toledo

Clipper On Line
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Uppercase in textbox (HMG4)

Post by mrduck »

pctoledo wrote:mrduck, need only change:

Code: Select all

   DATA nMaxLength                                INIT   0
Thanks!

done, sorry
Post Reply