FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour copy and paste doubt
Posts: 253
Joined: Wed May 25, 2016 01:04 AM
copy and paste doubt
Posted: Fri Aug 09, 2024 04:59 PM

Hi,

Is there any way to remove some characters from the copied text before it is pasted into a field? Let me explain: the copied text is 02.220.045/0002-04 and I need to paste it into a specific get to paste 02220045000204.

Tia.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: copy and paste doubt
Posted: Fri Aug 09, 2024 06:09 PM
Please try:
Code (fw): Select all Collapse
function TestGetPic

   local oDlg, oGet
   local cGet  := Space( 20 )

   DEFINE DIALOG oDlg SIZE 200,200 PIXEL TRUEPIXEL
   @ 30,30 GET oGet VAR cGet PICTURE REPLICATE( "9", Len( cGet ) ) ;
      SIZE 150,20 PIXEL OF oDlg
   oGet:bChange := { |k,f,o| MyGetChange( k,f,o ) }
   @ 80,30 BUTTON "OK" SIZE 80,30 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

return nil

static function MyGetChange( k, f, oGet )

   local cText    := oGet:cText
   local cNew     := ""
   local n, c

   if k == nil
      for n := 1 to Len( cText )
         if ISDIGIT( c := SubStr( cText, n, 1 ) )
            cNew  += c
         endif
      next

      if !( cNew == cText )
         oGet:cText  := PadR( cNew, Len( cText ) )
      endif
   endif

return .t.
Regards



G. N. Rao.

Hyderabad, India
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: copy and paste doubt
Posted: Fri Aug 09, 2024 06:11 PM
Code (fw): Select all Collapse
// C:\FWH\SAMPLES\CNPJ.PRG - 09/08/2024 - By Joao Santos.

#Include "FiveWin.ch"

STATIC oWnd

FUNCTION Main()

   LOCAL oDlg, oFont, aGet := ARRAY(3)
   LOCAL cCnpj1 := SPACE(18), cCnpj2 := SPACE(14)

   cCnpj1 := "02.220.045/0002-04" // only test

   DEFINE FONT oFont NAME "FIXEDSYS" SIZE 10, -14 BOLD

   DEFINE DIALOG oDlg FROM 1, 1 TO 400, 600 TITLE "wArtiaga: Converter CNPJ"  ;
      STYLE nOr( WS_POPUP, WS_VISIBLE, WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, ;
                 WS_MINIMIZEBOX, WS_MAXIMIZEBOX ) PIXEL OF oWnd

   @ 30, 28 SAY "Copie o CNPJ a Converter:" OF oDlg PIXEL                     ;
      COLORS CLR_HBLUE, CLR_WHITE SIZE 200, 10 TRANSPARENT UPDATE FONT oFont

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   @ 45, 28 GET aGet[1] VAR cCnpj1 OF oDlg PICTURE "99.999.999/9999-99"       ;
      PIXEL SIZE 100, 12 FONT oFont CENTER COLORS CLR_BLACK, CLR_WHITE

   @ 70, 28 SAY "Novo CNPJ Convertido:"  OF oDlg PIXEL                        ;
      COLORS CLR_HRED, CLR_WHITE SIZE 200, 10 TRANSPARENT UPDATE FONT oFont

   @ 85, 28 GET aGet[2] VAR cCnpj2 OF oDlg PICTURE "@R 99999999999999"        ;
      PIXEL SIZE 100, 12 FONT oFont CENTER COLORS CLR_BLACK, CLR_WHITE

   @ 140, 30 BTNBMP PROMPT "&Converter CNPJ" SIZE 080, 40 PIXEL OF oDlg FLAT  ;
   ACTION( CONVERTER_CNPJ_CLIENTE( aGet, cCnpj1 ) ) FONT oFont

   @ 140, 120 BTNBMP PROMPT "&Salida" SIZE 050, 40 PIXEL OF oDlg FLAT         ;
   ACTION( oDlg:End() ) FONT oFont

   ACTIVATE DIALOG oDlg CENTERED

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   oFont:End()

RETURN NIL

FUNCTION CONVERTER_CNPJ_CLIENTE( aGet, cCnpj1 )

   cCnpj1 := StrTran( cCnpj1, ".", "" )
   cCnpj1 := StrTran( cCnpj1, "/", "" )
   cCnpj1 := StrTran( cCnpj1, "-", "" )
   cCnpj1 := AllTrim( cCnpj1 )

   ? cCnpj1, "02220045000204" // perfecto!

   aGet[2]:VARPUT( cCnpj1 )
   aGet[2]:Refresh()

RETURN NIL

// FIN / END - kapiabafwh@gmail.com
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: copy and paste doubt
Posted: Fri Aug 09, 2024 06:57 PM
From the next version, we are introducing a new
Code (fw): Select all Collapse
DATA bPaste
in the class TGet class

In case of paste, bPaste will be evaluated with PasteText and the Get Object.

Then it will be much easier to handle any such special requirements:
Then the program can be something like this.
Code (fw): Select all Collapse
function TestGetPic

   local oDlg, oGet
   local cGet  := Space( 20 )

   DEFINE DIALOG oDlg SIZE 200,200 PIXEL TRUEPIXEL
   @ 30,30 GET oGet VAR cGet PICTURE REPLICATE( "9", Len( cGet ) ) ;
      SIZE 150,20 PIXEL OF oDlg
   oGet:bPaste := <|cPaste,oGet|
      local cText := ""
      local c
      for each c in cPaste
         if ISDIGIT( c ); cText += c; endif
      next
      oGet:cText := PadR( cText, Len( oGet:cText ) )
      return nil
      >

   @ 80,30 BUTTON "OK" SIZE 80,30 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 253
Joined: Wed May 25, 2016 01:04 AM
Re: copy and paste doubt
Posted: Fri Aug 09, 2024 07:36 PM
nageswaragunupudi wrote:Please try:
Code (fw): Select all Collapse
function TestGetPic

   local oDlg, oGet
   local cGet  := Space( 20 )

   DEFINE DIALOG oDlg SIZE 200,200 PIXEL TRUEPIXEL
   @ 30,30 GET oGet VAR cGet PICTURE REPLICATE( "9", Len( cGet ) ) ;
      SIZE 150,20 PIXEL OF oDlg
   oGet:bChange := { |k,f,o| MyGetChange( k,f,o ) }
   @ 80,30 BUTTON "OK" SIZE 80,30 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

return nil

static function MyGetChange( k, f, oGet )

   local cText    := oGet:cText
   local cNew     := ""
   local n, c

   if k == nil
      for n := 1 to Len( cText )
         if ISDIGIT( c := SubStr( cText, n, 1 ) )
            cNew  += c
         endif
      next

      if !( cNew == cText )
         oGet:cText  := PadR( cNew, Len( cText ) )
      endif
   endif

return .t.
Mr. Nages your example works very well but i use .res and when pasting it shows fewer characters, just 74167222000 any idea? Tia.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: copy and paste doubt
Posted: Sun Aug 11, 2024 05:20 AM
i use .res and when pasting it shows fewer characters, just 74167222000 any idea
res or source code, the issue is the same.
This works well if the length of your variable is 20 chars or more.

Please let me know the FWH version you are using. I can suggest a modification to TGet.prg to use my 2nd example.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: copy and paste doubt
Posted: Mon Aug 12, 2024 09:42 AM
:D
nageswaragunupudi wrote:From the next version, we are introducing a new
Code (fw): Select all Collapse
DATA bPaste
in the class TGet class

In case of paste, bPaste will be evaluated with PasteText and the Get Object.

Then it will be much easier to handle any such special requirements:
Then the program can be something like this.
Code (fw): Select all Collapse
function TestGetPic

   local oDlg, oGet
   local cGet  := Space( 20 )

   DEFINE DIALOG oDlg SIZE 200,200 PIXEL TRUEPIXEL
   @ 30,30 GET oGet VAR cGet PICTURE REPLICATE( "9", Len( cGet ) ) ;
      SIZE 150,20 PIXEL OF oDlg
   oGet:bPaste := <|cPaste,oGet|
      local cText := ""
      local c
      for each c in cPaste
         if ISDIGIT( c ); cText += c; endif
      next
      oGet:cText := PadR( cText, Len( oGet:cText ) )
      return nil
      >

   @ 80,30 BUTTON "OK" SIZE 80,30 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

return nil
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 253
Joined: Wed May 25, 2016 01:04 AM
Re: copy and paste doubt
Posted: Mon Aug 12, 2024 11:17 AM
nageswaragunupudi wrote:
i use .res and when pasting it shows fewer characters, just 74167222000 any idea
res or source code, the issue is the same.
This works well if the length of your variable is 20 chars or more.

Please let me know the FWH version you are using. I can suggest a modification to TGet.prg to use my 2nd example.
Mr. Nages, Fwh1811

Tia.
Posts: 253
Joined: Wed May 25, 2016 01:04 AM
Re: copy and paste doubt
Posted: Thu Aug 15, 2024 02:21 PM
karinha wrote:
Code (fw): Select all Collapse
// C:\FWH\SAMPLES\CNPJ.PRG - 09/08/2024 - By Joao Santos.

#Include "FiveWin.ch"

STATIC oWnd

FUNCTION Main()

   LOCAL oDlg, oFont, aGet := ARRAY(3)
   LOCAL cCnpj1 := SPACE(18), cCnpj2 := SPACE(14)

   cCnpj1 := "02.220.045/0002-04" // only test

   DEFINE FONT oFont NAME "FIXEDSYS" SIZE 10, -14 BOLD

   DEFINE DIALOG oDlg FROM 1, 1 TO 400, 600 TITLE "wArtiaga: Converter CNPJ"  ;
      STYLE nOr( WS_POPUP, WS_VISIBLE, WS_CAPTION, WS_THICKFRAME, WS_SYSMENU, ;
                 WS_MINIMIZEBOX, WS_MAXIMIZEBOX ) PIXEL OF oWnd

   @ 30, 28 SAY "Copie o CNPJ a Converter:" OF oDlg PIXEL                     ;
      COLORS CLR_HBLUE, CLR_WHITE SIZE 200, 10 TRANSPARENT UPDATE FONT oFont

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   @ 45, 28 GET aGet[1] VAR cCnpj1 OF oDlg PICTURE "99.999.999/9999-99"       ;
      PIXEL SIZE 100, 12 FONT oFont CENTER COLORS CLR_BLACK, CLR_WHITE

   @ 70, 28 SAY "Novo CNPJ Convertido:"  OF oDlg PIXEL                        ;
      COLORS CLR_HRED, CLR_WHITE SIZE 200, 10 TRANSPARENT UPDATE FONT oFont

   @ 85, 28 GET aGet[2] VAR cCnpj2 OF oDlg PICTURE "@R 99999999999999"        ;
      PIXEL SIZE 100, 12 FONT oFont CENTER COLORS CLR_BLACK, CLR_WHITE

   @ 140, 30 BTNBMP PROMPT "&Converter CNPJ" SIZE 080, 40 PIXEL OF oDlg FLAT  ;
   ACTION( CONVERTER_CNPJ_CLIENTE( aGet, cCnpj1 ) ) FONT oFont

   @ 140, 120 BTNBMP PROMPT "&Salida" SIZE 050, 40 PIXEL OF oDlg FLAT         ;
   ACTION( oDlg:End() ) FONT oFont

   ACTIVATE DIALOG oDlg CENTERED

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   oFont:End()

RETURN NIL

FUNCTION CONVERTER_CNPJ_CLIENTE( aGet, cCnpj1 )

   cCnpj1 := StrTran( cCnpj1, ".", "" )
   cCnpj1 := StrTran( cCnpj1, "/", "" )
   cCnpj1 := StrTran( cCnpj1, "-", "" )
   cCnpj1 := AllTrim( cCnpj1 )

   ? cCnpj1, "02220045000204" // perfecto!

   aGet[2]:VARPUT( cCnpj1 )
   aGet[2]:Refresh()

RETURN NIL

// FIN / END - kapiabafwh@gmail.com
Regards, saludos.
Thank you Karinha!

Continue the discussion