|
Post by tonywyc on Feb 17, 2022 17:46:34 GMT -5
Good day and want to thank you for any help.
1. What is best method to catch if some one press enter on a string field with out enter anything?
Thanks
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Feb 17, 2022 18:08:16 GMT -5
Check for a Chr$(13) keypress.
|
|
|
Post by Walt Decker on Feb 17, 2022 18:24:56 GMT -5
It depends on the control. If you are using a graphic control (box or window) you can check for CHR$(13).
If you are using an edit control (TEXTBOX) you can not unless you change the stylebits to ES_MULTILINE AND ES_WANTRETURN. Then you have to use an API call to check for the key state of VK_RETURN.
If you are using a TEXTWINDOW or TEXTEDITOR you can not.
|
|
|
Post by Brandon Parker on Feb 17, 2022 22:45:12 GMT -5
If you are using a text control and you have a way set up to trigger code when the Enter key is pressed, you can just check the contents of the text control. If the variable that the contents are stored in equals an empty string ( "" ) then the user did not enter any information.
{:0)
Brandon Parker
|
|
|
Post by tonywyc on Feb 18, 2022 3:09:40 GMT -5
Let me stat off and thank you for your answers.
My program is just running in main windows like a traditional basic programs. This is simple key program to build a load file for my next program
so if some one press enter then it is Char$(13)
Now expanding on String fields if you have an array and you do not populate element then will it value be blank " " ?
|
|
|
Post by tsh73 on Feb 18, 2022 5:48:21 GMT -5
Nope In a mainwin, if you press Enter on an Input statement, you'll get empty line
Input "Hello. What's your name? ";name$
if name$="" then print "It looks you just pressed ENTER" else print "Hello ";name$ end if
If your Input expects number, then Enter will give 0
if age=0 then print "It looks you just pressed ENTER" else print "Such a fine age - ";age end if
It will be empty string
dim a$(20) if a$(1)="" then print "Un-intialised string array contains empty strings"
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Feb 18, 2022 10:22:11 GMT -5
Right out of Help:
'accept characters and display them until Enter is pressed text$ = "" while c$ <> chr$(13) c$ = input$(1) print c$; if c$ <> chr$(13) then text$ = text$ + c$ wend print ' I added this print "You typed:"; text$ end
|
|
|
Post by Rod on Feb 18, 2022 11:20:17 GMT -5
As we are seeing there are several forms of input. So most everyone is right. But which is right for the Original Poster.
Well some code would get the most appropriate response. So show us a little more of the program you are writing.
|
|
rnbw
New Member
Posts: 48
|
Post by rnbw on Feb 18, 2022 11:37:05 GMT -5
It depends on the control. If you are using a graphic control (box or window) you can check for CHR$(13). If you are using an edit control (TEXTBOX) you can not unless you change the stylebits to ES_MULTILINE AND ES_WANTRETURN. Then you have to use an API call to check for the key state of VK_RETURN. If you are using a TEXTWINDOW or TEXTEDITOR you can not. I am struggling with this. Could you give a quick example?
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Feb 18, 2022 13:17:18 GMT -5
It depends on the control. If you are using a graphic control (box or window) you can check for CHR$(13). If you are using an edit control (TEXTBOX) you can not unless you change the stylebits to ES_MULTILINE AND ES_WANTRETURN. Then you have to use an API call to check for the key state of VK_RETURN. If you are using a TEXTWINDOW or TEXTEDITOR you can not. I am struggling with this. Could you give a quick example? It is rather complicated but here is example straight out of Help: 'a simple keycheck program open "Press some keys!" for graphics_nsb as #draw ' need graphics screen #draw "setfocus;place 10 20" ' <<<<<<<<<< need this with key catching #draw "when characterInput keyCheck" ' <<<<<<<<<< setup for catching keypresses wait
sub keyCheck handle$, key$ ' <<<<<<<<< sub for handling the key presses #handle$, "\";key$ end sub
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Feb 18, 2022 13:24:58 GMT -5
As we are seeing there are several forms of input. So most everyone is right. But which is right for the Original Poster. Well some code would get the most appropriate response. So show us a little more of the program you are writing. He mentions working in Main screen so I am right (in (my) 2nd post of this thread) ;-)) What the heck is "string fields", I leave to your imagination but does sound a little like a textbox which you can't use in main window, sounds more like a data base record that does have string fields or struct (which I had just discovered last night looking for a Single Type in Walt Decker's crazy code demo for arc drawing). tonywyc take tsh73's hint and use Input for getting strings in Main window.
|
|
rnbw
New Member
Posts: 48
|
Post by rnbw on Feb 19, 2022 11:02:49 GMT -5
I am struggling with this. Could you give a quick example? It is rather complicated but here is example straight out of Help: 'a simple keycheck program open "Press some keys!" for graphics_nsb as #draw ' need graphics screen #draw "setfocus;place 10 20" ' <<<<<<<<<< need this with key catching #draw "when characterInput keyCheck" ' <<<<<<<<<< setup for catching keypresses wait
sub keyCheck handle$, key$ ' <<<<<<<<< sub for handling the key presses #handle$, "\";key$ end sub
I was looking for using Chr$(13) in a multiline textbox. I'm having a mental block at the moment. Old age!
|
|
bplus
Full Member
Posts: 127
|
Post by bplus on Feb 19, 2022 12:18:59 GMT -5
Old, yeah, I know that feeling in a 100 different ways!
Uhm, do you want chr$(13) to know when the user has completed a textbox and you want to start processing contents? Sorta like enter for an Input.
Because then one usually sets up a button to click to get the processing of textbox(s) going, like filling out a form and then click for processing.
|
|
rnbw
New Member
Posts: 48
|
Post by rnbw on Feb 19, 2022 14:21:31 GMT -5
Old, yeah, I know that feeling in a 100 different ways! Uhm, do you want chr$(13) to know when the user has completed a textbox and you want to start processing contents? Sorta like enter for an Input. Because then one usually sets up a button to click to get the processing of textbox(s) going, like filling out a form and then click for processing. No, I'm looking for Chr$(13) starting a new line in a multi-line textbox.
|
|
|
Post by tsh73 on Feb 19, 2022 15:34:34 GMT -5
Probably it is possible But what are you going to do with that?
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
TexteditorColor$ = "palegray" texteditor #main.log, 275, 27, 255, 320 TexteditorColor$ = "white" texteditor #main.textedit3, 5, 27, 255, 320 statictext #main.statictext1, "Enter text here", 5, 5, 84, 20 statictext #main.statictext4, "This is log panel", 275, 2, 98, 20
'-----End GUI objects code
open "getting ENTER from a textbox" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]" handle2Check = HWND(#main.textedit3) ' #main.log "!disable" timer 100, [tick]
[main.inputLoop] 'wait here for input event wait
[quit.main] 'End the program timer 0 close #main end
[tick] 'is textbox active? lastHandle = handle CallDLL #user32, "GetFocus", handle As long if handle <> handle2Check then wait 'else check if Enter was pressed keycode = 13 CallDLL #user32, "GetAsyncKeyState", keycode As long, _ result As short if lastHandle <> handle then wait 'ignore keypress left from previous control if result<>0 then #main.log "Got Enter pressed" wait
|
|