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
Has thanked: 3 times
Been thanked: 7 times
Contact:

Uppercase in textbox (HMG4)

Post by pctoledo » Fri Jul 29, 2011 2:08 am

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
Has thanked: 3 times
Been thanked: 7 times
Contact:

Post by pctoledo » Sun Jul 31, 2011 11:19 am

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
Has thanked: 3 times
Been thanked: 7 times
Contact:

Post by pctoledo » Sun Jul 31, 2011 12:42 pm

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
Has thanked: 3 times
Been thanked: 7 times
Contact:

Post by pctoledo » Mon Aug 01, 2011 12:14 pm

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: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Mon Aug 01, 2011 1:16 pm

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

Post by mrduck » Tue Aug 02, 2011 8:00 am

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
Has thanked: 3 times
Been thanked: 7 times
Contact:

Post by pctoledo » Tue Aug 02, 2011 11:22 am

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

Post by mrduck » Wed Aug 03, 2011 9:36 am

Patch commited to svn

please check

User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Has thanked: 3 times
Been thanked: 7 times
Contact:

Post by pctoledo » Wed Aug 03, 2011 11:15 am

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

Post by mrduck » Wed Aug 03, 2011 1:01 pm

pctoledo wrote:mrduck, need only change:

Code: Select all

   DATA nMaxLength                                INIT   0
Thanks!

done, sorry

Post Reply