Limitar input por caracteres y no por espacio

Limitar input por caracteres y no por espacio

Postby Hector Pedro Lerda » Tue Feb 02, 2021 10:32 pm

Buenas tardes,

Soy Nicolás, hijo de Pedro y estoy haciendo continuidad de sus sistemas, y pregunto a traves de su cuenta hasta que habiliten la mia.

Una gran duda existencial que tuve siempre, es el por qué se debe delimetrar el GET a traves de espacios en blancos y no simplemente ponerle un limite de caracteres. Ya que al generar que la variable tenga, por ejemplo, 20 espacios en blanco, hace que siempre queden espacios al final del input. Los usuarios en otras aplicaciones, cuando quieren editar, hacen click en cualquier parte del final del input y lo deberia llevar a la ultima letra, en nuestro caso lo lleva a un espacio en mitad del input en vez de la ultima letra (que en realidad, el espacio es el ultimo caracter).

Esto genera molestias en el UX.

Adjunto mi codigo ejemplo:

Code: Select all  Expand view

 vnum[1]:=space(30)
 vnum[2]:=space(30)
 vnum[3]:=space(3)
 vnum[4]:=space(30)
 vnum[5]:=space(30)

// Defino un alias al recurso de la pantalla
DEFINE DIALOG d_loc2 RESOURCE "dl_apocap"

//Redefino fuentes y colores
redefine say  id 4005 of d_loc2 color METRO_GRIS7A, METRO_GRIS4  font oFuenteL
redefine say gnum[6] prompt vnum[6]  id 4001 of d_loc2 color METRO_GRIS4  font oFuenteM update

// Asigno variables a los inputs.
redefine GET gnum[1] var vnum[1]           id 4023 of d_loc2  picture  "@!" color CLR_3  update
redefine GET gnum[2] var vnum[2]           id 4025 of d_loc2  picture  "@!"  color CLR_3  update
redefine GET gnum[3] var hvnum["moneda"]   id 4011 of d_loc2  picture  "@!" color CLR_3  update
redefine GET gnum[4] var hvnum["ingreso"]  id 4017 of d_loc2  picture  "@e 9,999,999.9999"  color CLR_3  update
redefine GET gnum[5] var vnum[5]           id 4002 of d_loc2  picture  "@!" color CLR_3  update


Estuve investigando tanto aqui, como en los docs de Harbour y no encuentro nada.

Solo encontre algo de LimitText( -1 ) para dejarlo libre, pero no me funciona. Me dice "No exported method".

Lo uso de la siguiente manera:

Code: Select all  Expand view

// Despues del redefine GET. Probe primero uno, y despues el otro. En el primero no genera nada, en el segundo da el error de N.E.M.
gnum[5]:LimitText( -1 )
vnum[5]:LimitText( -1 )


Si tienen una solución de delimetrar el input sin tener que usar espacios en blanco, se lo agradeceria muchisimo.

Nicolás Lerda.
User avatar
Hector Pedro Lerda
 
Posts: 46
Joined: Tue May 07, 2013 7:27 pm
Location: Buenos Aires - Argentina

Re: Limitar input por caracteres y no por espacio

Postby nageswaragunupudi » Wed Feb 03, 2021 8:52 am

If the user presses <END> key the cursor goes next to the last non-space character, as you wanted.
Clicking at any place will take the cursor to that place even if there are spaces. This has been the behavior of Get class since ages.

Limittext value of -1 is for multiline edit.
For single line edit it is 0. In any case normal ANSI get ignores this setting.

FWH provides EDIT class which behaves the way you want.

Please try this:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oDlg, oFont
   local aVar  := { "", "", 234.0, "" }
   local aGet[ 4 ]

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 400,500 PIXEL TRUEPIXEL FONT oFont

   @  20,20 SAY "1" SIZE 40,20 PIXEL OF oDlg
   @  50,20 SAY "2" SIZE 40,20 PIXEL OF oDlg
   @  80,20 SAY "3" SIZE 40,20 PIXEL OF oDlg
   @ 110,20 SAY "4" SIZE 40,20 PIXEL OF oDlg

   @  20,80 EDIT aGet[ 1 ] VAR aVar[ 1 ] SIZE 200,24 PIXEL OF oDlg LIMITTEXT BY 10 CHARS UPDATE
   @  50,80 EDIT aGet[ 2 ] VAR aVar[ 2 ] SIZE 200,24 PIXEL OF oDlg LIMITTEXT BY 10 CHARS UPDATE
   @  80,80 GET  aGet[ 3 ] VAR aVar[ 3 ] PICTURE "999,999.99" SIZE 100,24 PIXEL OF oDlg RIGHT UPDATE
   @ 110,80 EDIT aGet[ 4 ] VAR aVar[ 4 ] SIZE 200,24 PIXEL OF oDlg LIMITTEXT BY 10 CHARS UPDATE

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Limitar input por caracteres y no por espacio

Postby Hector Pedro Lerda » Wed Feb 03, 2021 11:11 am

Thanks Nages for your answer.

Yes, it works. But I'm working with DLL Dialogs.

This is my code example:

Code: Select all  Expand view

function main()
local gnum, vnum
   
    DEFINE DIALOG d_loc2 RESOURCE "dl_apocap"
// THIS COMPILE AND WORKS
   redefine EDIT gnum var vnum id 4002 of d_loc2

   ACTIVATE DIALOG d_loc2 CENTERED
return nil
 


But when I put "LIMITTEXT BY 10 CHARS UPDATE" I cannot compile it anymore, through this error:

No code generated.
test.prg(2810) Error E0030 Syntax error "syntax error at 'EDIT'"
* Compile errors *


Code: Select all  Expand view

function main()
local gnum, vnum
   
    DEFINE DIALOG d_loc2 RESOURCE "dl_apocap"

   redefine EDIT gnum var vnum id 4002 of d_loc2 LIMITTEXT BY 10 CHARS UPDATE

   ACTIVATE DIALOG d_loc2 CENTERED
return nil
 


What am I doing wrong?

Thank you so much for your time and patience.
User avatar
Hector Pedro Lerda
 
Posts: 46
Joined: Tue May 07, 2013 7:27 pm
Location: Buenos Aires - Argentina

Re: Limitar input por caracteres y no por espacio

Postby nageswaragunupudi » Wed Feb 03, 2021 12:13 pm

Please try
Code: Select all  Expand view
redefine EDIT gnum var vnum id 4002 of d_loc2 UPDATE
gnum:setlimittext(10)
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Limitar input por caracteres y no por espacio

Postby nlerdafehn » Thu Feb 04, 2021 7:49 pm

Hi, sorry for the delay.

Code: Select all  Expand view
redefine EDIT gnum var vnum id 4002 of d_loc2 UPDATE
gnum:setlimittext(10)


It gives me this error while compiling:

Error E0030 Syntax error "syntax error at 'EDIT'"


If I put away the UPDATE statement, It's compile fine, but it doesn't limit the input.
Nicolás
nlerdafehn
 
Posts: 50
Joined: Tue Feb 02, 2021 10:21 pm
Location: Buenos Aires, Argentina

Re: Limitar input por caracteres y no por espacio

Postby nageswaragunupudi » Fri Feb 05, 2021 12:37 am

Please use the "gnum:setlimittext(10)" in ON INIT clause of the dialog.
Code: Select all  Expand view

ACTIVATE DIALOG oDlg ON INIT gnum:setlimittext(10)
 



May I know the FWH version you are using?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Limitar input por caracteres y no por espacio

Postby nageswaragunupudi » Fri Feb 05, 2021 1:43 am

Please test this sample program:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oDlg, oFont
   local aVar  := { PadR( "get1", 10 ), "edit", "", PadR( "pwd", 10 ) }
   local aGet[ 4 ]

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE DIALOG oDlg RESOURCE "TESTGETS" FONT oFont

   REDEFINE GET  aGet[ 1 ] VAR aVar[ 1 ] ID 101
   REDEFINE EDIT aGet[ 2 ] VAR aVar[ 2 ] ID 102
   REDEFINE EDIT aGet[ 3 ] VAR aVar[ 3 ] ID 103
   REDEFINE GET  aGet[ 4 ] VAR aVar[ 4 ] ID 104

   ACTIVATE DIALOG oDlg CENTERED ON INIT ( ;
      aGet[ 2 ]:SetLimitText(  8 ), ;
      aGet[ 3 ]:SetLimitText( 10 ) )

   RELEASE FONT oFont

   ? FW_ArrayAsList( aVar )

return nil


rc file:
Code: Select all  Expand view

TESTGETS DIALOG 99, 89, 194, 250
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "TESTGETS"
FONT 8, "MS Sans Serif"
{
 EDITTEXT 101, 33, 51, 131, 12, WS_BORDER | WS_TABSTOP
 EDITTEXT 102, 33, 71, 131, 12, WS_BORDER | WS_TABSTOP
 EDITTEXT 103, 33, 91, 131, 12, WS_BORDER | WS_TABSTOP
 EDITTEXT 104, 33,111, 131, 12, ES_PASSWORD | WS_BORDER | WS_TABSTOP
 DEFPUSHBUTTON "OK", 1, 42, 200, 50, 14
 PUSHBUTTON "Cancel", 2, 102, 200, 50, 14
}
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Limitar input por caracteres y no por espacio

Postby nageswaragunupudi » Fri Feb 05, 2021 4:27 am

Added clauses UPDATE and LIMITTEXT [BY n CHARS] to REDEFINE EDIT command in FWH 2101
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Otto and 64 guests