Horizon
Member in Training
Posts: 32
|
Post by Horizon on Jul 20, 2021 21:30:26 GMT
Hello,
I was wondering how you can use the 'Enter' key to execute your input in a textbox. Here is an example program (without the Enter function). Is there a way of detecting the 'Enter' key press to activate [sendString]?
nomainwin UpperLeftX = 50 UpperLeftY = 50 WindowWidth = 400 WindowHeight = 100
statictext #main, "Enter a string", 20, 10, 144, 20 textbox #main.wantedString, 20, 30, 144, 25 button #main.sendString, "Send", [sendString], UL, 180, 30, 90, 25 button #main.clearString, "Clear", [main.InputLoop], UL, 280, 30, 90, 25
open "Show myString" for window as #main print #main, "trapclose [quit]"
[main.InputLoop] print #main.wantedString, "" print #main.wantedString, "!setfocus" wait
[sendString] print #main.wantedString, "!contents?" input #main.wantedString, a$ if a$ = "" then [trapError] notice "You entered: ";a$ goto [main.InputLoop]
[trapError] notice "Please ener a string!" goto [main.InputLoop]
[quit] close #main end
|
|
|
Post by cundo on Jul 21, 2021 1:46:44 GMT
The easiest way would be to use a Dialog type window and a .default button
|
|
|
Post by tsh73 on Jul 21, 2021 6:01:12 GMT
from the help file
Default Button A window of type DIALOG can contain a button with the extension ".default". If the user presses the ENTER key while the dialog window has focus, it is the same as if the button whose extension is "default" is pressed and program execution will continue at the event handler [branchLabel] for that button. In the example below, the program will branch to the [okay] routine when the user presses ENTER.
button #win.default, "Okay",[okay],UL,200,100 open "Test" for dialog as #win
|
|
|
Post by Rod on Jul 21, 2021 6:32:55 GMT
The next issue you will face is getting input from more than one text box, a form say. The usual solution is to display one Enter button that the user can press when the form is complete. No need for this to be dialogue or default, plain simple button and handler will do.
In your example you already have that button, it is called Send, just read the contents of the text box when that button is pressed.
|
|
Horizon
Member in Training
Posts: 32
|
Post by Horizon on Jul 21, 2021 18:13:55 GMT
The 'win.default' solution works really well, I appreciate the tip. I think the best way to execute the this kind of program would be...
Add an appropriate 'Enter' button Set the correct tab order to hop sequentially between the entry fields (textboxes) On pressing enter grab the contents of all entry fields and validate the input If missing field(s) notify If incorrect entry notify else write the data etc.
Thanks again
|
|