copy and paste doubt

copy and paste doubt

Postby wartiaga » Fri Aug 09, 2024 4: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.
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am

Re: copy and paste doubt

Postby nageswaragunupudi » Fri Aug 09, 2024 6:09 pm

Please try:
Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: copy and paste doubt

Postby karinha » Fri Aug 09, 2024 6:11 pm

Code: Select all  Expand view  RUN

// 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
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: copy and paste doubt

Postby nageswaragunupudi » Fri Aug 09, 2024 6:57 pm

From the next version, we are introducing a new
Code: Select all  Expand view  RUN
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: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: copy and paste doubt

Postby wartiaga » Fri Aug 09, 2024 7:36 pm

nageswaragunupudi wrote:Please try:
Code: Select all  Expand view  RUN
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.
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am

Re: copy and paste doubt

Postby nageswaragunupudi » Sun Aug 11, 2024 5: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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: copy and paste doubt

Postby Horizon » Mon Aug 12, 2024 9:42 am

:D
nageswaragunupudi wrote:From the next version, we are introducing a new
Code: Select all  Expand view  RUN
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: Select all  Expand view  RUN
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.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: copy and paste doubt

Postby wartiaga » 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.
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am

Re: copy and paste doubt

Postby wartiaga » Thu Aug 15, 2024 2:21 pm

karinha wrote:
Code: Select all  Expand view  RUN

// 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!
wartiaga
 
Posts: 212
Joined: Wed May 25, 2016 1:04 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests