# ...setting EditText() box lengths.

Earlier versions of win32lib had an EditText box entry length that was limited to the actual physical length of the box on the screen. This was of course determined in part by the size and type of font used in the box, making it very difficult to determine how many characters could be typed into the box.

This made it very difficult for you to handle the information typed into the box. If you were using the text string in a 'fixed length' database program for example, you not only had to possibly pad the data, you might instead have to truncate it !

Recent versions of win32lib use the ES_AUTOHSCROLL attribute by default, so that all EditText boxes are scrollable, and the characters you can type into the box are not determined by the physical box size.

So now, of course, if you wish to limit the field length to a certain number of characters, you can let Windows do it for you !
...just by using sendMessage() to limit the number of characters which can be typed into the box.

This program shows a simple example, in which the number of characters allowed will be 55, even though the physical size of the box is much smaller.

-- long_entry.exw

    -- long_entry.exw  -- a scrollable sle with a size limit.
    include win32lib.ew
    without warning    -- ( integer shift ) is not used in onKeySle1

    constant
    -- EM_LIMITTEXT   = #C5, -- now in win32lib.ew

      MyWin  = create( Window, "..enter a phrase up to 55 char..",
                      0, 0, 0, 460, 80, {#CC0000} ),  -- nothing but [x]
      Label1 = create( RText, "..then hit ENTER:", MyWin, 5, 5, 110, 20, 0 ),
      Sle1   = create( EditText, "", MyWin, 115, 3, 100, 22, 0 ),
      Label2 = create( LText, "", MyWin, 5, 27, 450, 22, 0 )

    procedure onOpen_MyWin(  integer self,  integer event,  sequence params  )
      integer i
      -- set for maximum 55 characters. using EM_LIMITTEXT(#C5).
      i=sendMessage( Sle1, EM_LIMITTEXT, 55, 0 )
    end procedure

    -- the ENTER key signals line completion.
    procedure onKey_Sle1(  integer self,  integer event,  sequence params  )
    -- transfer line to Label2 in main window.
      integer key = params[1]
      if key=13 then setText( Label2, getText( Sle1 ) ) end if
    end procedure

    setHandler(  MyWin,  w32HOpen,  routine_id( "onOpen_MyWin" )  )
    setHandler(  Sle1,  w32HKeyDown,  routine_id( "onKey_Sle1" )  )

    WinMain(MyWin,Normal)
    -- end --

Note that you will have to use sendMessage() for every EditText box whose maximum entry length you wish to control.

The addressbook examples in this tutorial don't really require a fixed length for the entry fields, because they use a comma/space field separator. However, because I'm using a simple message-box to confirm deletions, these boxes can become 'quite' messy with longer entries !

The last parameter in the MyWin 'creation' is simply a 'magic' number the same as:
or_all( {WS_CAPTION, WS_SYSMENU, WS_MINIMIZEBOX} ).
Previous versions of Win32lib would accept this number as a style parameter to *replace* the default window style, however, the latest Win32lib requires you to place this in a sequence, otherwise it will be *combined* with the default style, instead of replacing it !

..end of lesson.

CONTENTS