|
Post by pandawdy on Jul 7, 2019 12:01:02 GMT -5
I would like to limit input on a textbox to only two characters. Is that possible?
|
|
|
Post by mknarr on Jul 7, 2019 13:13:18 GMT -5
Yes. Here is an example of how I do it in a program.
hTextbox1=hwnd(#mailfile.tb1) ret=SendMessage(hTextbox1,_EM_LIMITTEXT,15,0)
You need to get the handle of the textbox (line 1) Then send a message to the textbox limiting the text (line 2)
In your case your numbers would be 2,0 limiting text to 2 characters.
|
|
|
Post by alincon on Jul 7, 2019 20:33:59 GMT -5
If you have a lot of textboxes to limit you can make a subroutine and call it for each textbox
call tbLimit hwnd(#main.textbox2),6 call tbLimit hwnd(#main.textbox3),5 call tbLimit hwnd(#main.textbox6),20 call cbLimit hwnd(#main.combobox5),15 call cbLimit hwnd(#main.combobox1),15 call cbLimit hwnd(#main.combobox2),15
sub tbLimit htext,hlmt calldll #user32, "SendMessageA",htext as word,_EM_LIMITTEXT as word, _ hlmt as word, 0 as long, r as long end sub
r.m.
|
|
|
Post by pandawdy on Aug 5, 2019 16:35:17 GMT -5
Is it possible to only allow numbers in a text box as a string value?
|
|
|
Post by tsh73 on Aug 6, 2019 1:19:27 GMT -5
found here on forum: ( variable number of handles) textbox #main.tb1, 130, 0, 40, 25 stylebits #main.tb1,_ES_NUMBER,0,0,0 'Set textbox to accept whole numbers only
|
|
|
Post by pandawdy on Aug 6, 2019 11:47:29 GMT -5
found here on forum: ( variable number of handles) textbox #main.tb1, 130, 0, 40, 25 stylebits #main.tb1,_ES_NUMBER,0,0,0 'Set textbox to accept whole numbers only Thank you for your help. Is there an online resource that explains how text boxers or other components can be limited or changed?
|
|
|
Post by tsh73 on Aug 6, 2019 12:50:45 GMT -5
|
|
|
Post by pandawdy on Aug 12, 2019 10:34:24 GMT -5
'-----Begin GUI objects code
statictext #main.statictext1, "Enter your own information or select from presets, then click SEND", 5, 5, 388, 20 ListboxColor$ = "white" listbox #main.presetlistbox, listboxlabel$(), [listbox2DoubleClick], 5, 47, 140, 495 TextboxColor$ = "white" textbox #main.labeltextbox, 190, 72, 100, 25 stylebits #main.labeltextbox,_EM_LIMITTEXT,10,0 statictext #main.statictext4, "LABEL (10 char.)", 190, 47, 101, 20 textbox #main.offsettextbox, 315, 72, 100, 25 statictext #main.statictext6, "OFFSET", 315, 47, 53, 20
textbox #main.dsttextbox, 440, 72, 100, 25 stylebits #main.dsttextbox,_ES_NUMBER,0,0,0 'THIS LINE FORCES THE TEXTBOX TO ACCEPT NUMBERS ONLY. statictext #main.statictext8, "DST", 440, 47, 108, 20
textbox #main.mode33offset, 560, 72, 100, 25 stylebits #main.mode33offset,_ES_NUMBER,0,0,0 'THIS LINE FORCES THE TEXTBOX TO ACCEPT NUMBERS ONLY. statictext #main.statictext10, "MODE 33 OFFSET", 560, 47, 113, 20
When setting up text boxes, _EM_LIMITTEXT doesn't work. But ES_NUMBER does. Why is this?
|
|
|
Post by pandawdy on Aug 12, 2019 10:44:34 GMT -5
If you have a lot of textboxes to limit you can make a subroutine and call it for each textbox call tbLimit hwnd(#main.textbox2),6 call tbLimit hwnd(#main.textbox3),5 call tbLimit hwnd(#main.textbox6),20 call cbLimit hwnd(#main.combobox5),15 call cbLimit hwnd(#main.combobox1),15 call cbLimit hwnd(#main.combobox2),15
sub tbLimit htext,hlmt calldll #user32, "SendMessageA",htext as word,_EM_LIMITTEXT as word, _ hlmt as word, 0 as long, r as long end sub
r.m. This works.. I just didn't understand that this required a DLL call while the stylebits didn't. Thanks.
|
|
|
Post by Chris Iverson on Aug 12, 2019 10:46:46 GMT -5
EM_LIMITTEXT is not a style, it's a message. Hence the different prefix on the name(ES vs EM. ES = Editbox Style; EM = Editbox Message).
That's why the above examples used the SendMessage API call to send the message to the textbox.
(Also, you can only send the message after the window is opened. There won't be anything to send the message to, otherwise.)
The reason it's not a style is because you need to have a way to specify how many characters you want to limit the box to, and there's no way to do that by editing window styles using stylebits. (The other parameters to the STYLEBITS command are different adjustments to the window's style; they're not general-use parameters. In order, the four parameters to STYLEBITS are styles you want to add to the window, styles you want to remove from the window, extended styles you want to add to the window, and extended styles you want to remove from the window.)
|
|