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.
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.
// 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
DATA bPaste
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
nageswaragunupudi wrote:Please try:
- Code: Select all Expand view
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.
i use .res and when pasting it shows fewer characters, just 74167222000 any idea
nageswaragunupudi wrote:From the next version, we are introducing a new
- Code: Select all Expand view
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
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
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.
karinha wrote:
- Code: Select all Expand view
// 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.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 23 guests