Page 1 of 1

GET con PICUTRE de 999999 y punto (.)

PostPosted: Mon Sep 18, 2023 8:56 pm
by FiveWiDi
Hola a todos,

Como debo especificar un PICTURE para un GET de una variable carácter (no numérica), que acepte sólo cifras y el punto (.)?

No doy con ello.

Muchas gracias,

Re: GET con PICUTRE de 999999 y punto (.)

PostPosted: Mon Sep 18, 2023 11:44 pm
by cmsoft
Si el punto siempre tiene que estar en la misma posicion, es posible usar el PICTURE "99999.99" (Esto tambien te dejará poner espacios)

En caso que el punto pueda estar en cualquier lado, puedes validarlo con una expresión regular
Code: Select all  Expand view

....
@ 2, 2 GET oGet VAR cText OF oDlg VALID(Validar(cText))
...

STATIC FUNCTION Validar(c)
   LOCAL cRegEx := hb_regexComp("^[0-9]+([.][0-9]+)?$")  
   LOCAL aMatch

   aMatch = hb_regex( cRegEx, c )
   if Empty(aMatch)
      MsgInfo('No válido')
   endif

return !Empty(aMatch)
 

Re: GET con PICUTRE de 999999 y punto (.)

PostPosted: Tue Sep 19, 2023 11:35 am
by FiveWiDi
cmsoft wrote:Si el punto siempre tiene que estar en la misma posicion, es posible usar el PICTURE "99999.99" (Esto tambien te dejará poner espacios)

En caso que el punto pueda estar en cualquier lado, puedes validarlo con una expresión regular
Code: Select all  Expand view

....
@ 2, 2 GET oGet VAR cText OF oDlg VALID(Validar(cText))
...

STATIC FUNCTION Validar(c)
   LOCAL cRegEx := hb_regexComp("^[0-9]+([.][0-9]+)?$")  
   LOCAL aMatch

   aMatch = hb_regex( cRegEx, c )
   if Empty(aMatch)
      MsgInfo('No válido')
   endif

return !Empty(aMatch)
 


De hecho estuve probando un método así utilizando VALID, pero pensé que podía existir un PICTURE para ello.
De momento lo resolveré así.
Gracias César,

Re: GET con PICUTRE de 999999 y punto (.)

PostPosted: Tue Sep 19, 2023 5:55 pm
by nageswaragunupudi
Please try:
Code: Select all  Expand view
function GetDigits()

   local oDlg, oGet, cGet, cPic

   cGet  := Space( 8 )
   cPic  := "99999.99"

   DEFINE DIALOG oDlg SIZE 300,160 PIXEL TRUEPIXEL

   @ 40,40 GET oGet VAR cGet PICTURE cPic SIZE 100,20 PIXEL OF oDlg

   @ 80,40 BUTTON "OK" SIZE 60,40 PIXEL OF oDlg ACTION MsgInfo( cGet )

   ACTIVATE DIALOG oDlg CENTERED

   ? cGet
return nil 

Re: GET con PICUTRE de 999999 y punto (.)

PostPosted: Tue Sep 19, 2023 6:12 pm
by FiveWiDi
nageswaragunupudi wrote:Please try:
Code: Select all  Expand view
function GetDigits()

   local oDlg, oGet, cGet, cPic

   cGet  := Space( 8 )
   cPic  := "99999.99"

   DEFINE DIALOG oDlg SIZE 300,160 PIXEL TRUEPIXEL

   @ 40,40 GET oGet VAR cGet PICTURE cPic SIZE 100,20 PIXEL OF oDlg

   @ 80,40 BUTTON "OK" SIZE 60,40 PIXEL OF oDlg ACTION MsgInfo( cGet )

   ACTIVATE DIALOG oDlg CENTERED

   ? cGet
return nil 


Thanks Mr. Rao

But the dot is not allways at the same position.
:(

Re: GET con PICUTRE de 999999 y punto (.)

PostPosted: Tue Sep 19, 2023 6:17 pm
by karinha
Code: Select all  Expand view

   cPic  := "########"
 


Regards, saludos.

Re: GET con PICUTRE de 999999 y punto (.)

PostPosted: Tue Sep 19, 2023 6:34 pm
by FiveWiDi
karinha wrote:
Code: Select all  Expand view

   cPic  := "########"
 


Regards, saludos.


Thanks Mr. João,

For me is ok, accept "0123456789.-+"