I've been trying to achieve this for ages but cannot work out what is wrong.
I simply want to allow BOTH the tab key and the enter key to allow a change of focus from one edit box to another.
Will this only work with edit boxes in a window, or can I use it also with a dialog box?
In the two examples following, the first one DOESN'T work. The second (using a window) does. It may be to do with the coding in the handler but despite making changes for some time, I can't understand why it won't work. (I know I've put Setcontrolnotify in twice in the first example, but that was because I wasn't sure where to initialise the code. It doesn't work wherever I place it.)
'THIS DOESN'T WORK
dialog d1
createdialog d1,0,0,295,199,@CAPTION|@SYSMENU,0,"Caption",&handler
CONTROL d1,@EDIT,"Press Enter or TAB",83,39,124,27,@CTEDITAUTOH,5
CONTROL d1,@EDIT,"Second Edit Box",83,69,124,27,@CTEDITAUTOH,6
SETFONT d1,"Ariel",9,400,0,5
SETCONTROLNOTIFY(D1,5,1,1)
setcontrolnotify(D1,6,1,1)
domodal d1
SUB handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
SetFocus d1,5
SETCONTROLNOTIFY(D1,5,1,1)
setcontrolnotify(D1,6,1,1)
CASE @IDCLOSEWINDOW
CLOSEdialog d1, @idok
CASE @IDCONTROL
IF @CONTROLID = 5
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus D1,6
CASE @ENTABKEY
SetFocus D1,6
ENDSELECT
ENDIF
IF @CONTROLID = 6
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus D1,5
CASE @ENTABKEY
SetFocus D1,5
ENDSELECT
ENDIF
ENDSELECT
RETURN
ENDSUB
rem BUT THIS ONE DOES WORK. WHAT'S THE DIFFERENCE
WINDOW win
OPENWINDOW win,0,0,295,199,0,0,"Caption",&handler
CONTROL win,@EDIT,"Press Enter or TAB",83,39,124,27,0x50800000|@CTEDITAUTOH,5
CONTROL win,@EDIT,"Press Enter or TAB",83,79,124,27,0x50800000|@CTEDITAUTOH,6
SETFONT win,"Ariel",9,400,0,5
SETCONTROLNOTIFY(win,5,1,1)
setcontrolnotify(win,6,1,1)
CENTERWINDOW WIN
SetFocus win,5
WAITUNTIL win=0
END
SUB handler
SELECT @MESSAGE
CASE @IDCONTROL
IF @CONTROLID = 5
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus win,6
CASE @ENTABKEY
SetFocus win,6
ENDSELECT
ENDIF
IF @CONTROLID = 6
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus win,5
CASE @ENTABKEY
SetFocus win,5
ENDSELECT
ENDIF
'CASE @IDCREATE
'CENTERWINDOW WIN
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
ENDSELECT
RETURN
ENDSUB
Would be grateful if anyone could point out what's wrong.
Thanks.
Add a few more edit box styles Adrian .. :) You have 0x50800000 in your second example, although I try to avoid 'magic numbers' if I can, I'm never sure what they mean ..
@CTEDITMULTI | @CTEDITRETURN | @TABSTOP | @CTEDITAUTOH
seems to work OK ..
best wishes, :)
Graham
Thanks Graham. Will try it out.
Seasons Greetings
Adrian
I've now tried that, but unfortunately the enter key still doesn't work with the dialog box example. (The tab key is enabled by the @tabstop which is the default, I believe, for the control.)
I still can't get the enter key working through the setcontrolnotify code as in the window example.
Any further thoughts would be welcome.
Adrian
Silly me! :-[
I've just realised that I was not noticing there is a BIG difference between @idcontrol and @controlid. (Not even sure I was aware there were two different codes! I am now!)
What I was doing was coding: Case @controlid
If @controlid =5
instead of Case @idcontrol
if @controlid = 5
All now works perfectly.
Adrian
Adrian, could you post the code that works, for those of us who might also find it useful? I know I would find it useful, if nothing else as a learning experience on how to get edit boxes to work.
Thanks,
Bill
Here is the code I finally got to work I've also included a note (at the end of the code) of how I implemented it in my larger program with 19 edit boxes (A sort of 'To Do' list program) using a couple of for x=1 to 19:next x loops.
'THIS FINALLY WORKS
dialog d1
createdialog d1,0,0,295,199,@CAPTION|@SYSMENU,0,"Caption",&handler
CONTROL d1,@EDIT,"Press Enter or TAB",83,39,124,27,@cteditmulti|@CTEDITRETURN|@CTEDITAUTOH,5
CONTROL d1,@EDIT,"Second Edit Box",83,69,124,27,@cteditmulti|@CTEDITRETURN|@CTEDITAUTOH,6
SETFONT d1,"Ariel",9,400,0,5
domodal d1
SUB handler
SELECT @MESSAGE
case @idcontrol
IF @CONTROLID = 5
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus D1,6
CASE @ENTABKEY
SetFocus D1,6
ENDSELECT
ENDIF
IF @CONTROLID = 6
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus D1,5
CASE @ENTABKEY
SetFocus D1,5
ENDSELECT
ENDIF
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
SetFocus d1,5
SETCONTROLNOTIFY(D1,5,1,1)
setcontrolnotify(D1,6,1,1)
CASE @IDCLOSEWINDOW
CLOSEdialog d1, @idok
ENDSELECT
RETURN
ENDSUB
/* TO GET IT TO WORK IN MY PROGRAM, WITH 19 EDIT WINDOWS, I USED THE FOLLOWING CODE TO
SET IT UP
FOR X=1 TO 19
SETCONTROLNOTIFY D1,X,1,1
NEXT X
(WITH THE DIALOG BOX THIS HAS TO GO UNDER @IDINITDIALOG)
THEN IN THE D1_HANDLER THE FOLLOWING CODE
CASE @IDCONTROL
' ENTER KEY AND TAB WORK HERE IF CODED FOR SETCONTROLNOTIFY
X=0 'not sure if this is necessary
FOR X=1 TO 19
IF @CONTROLID = X
X=X+1
SELECT @NOTIFYCODE
CASE @ENENTERKEY
SetFocus D1,X
CASE @ENTABKEY
SetFocus D1,X
ENDSELECT
ENDIF
NEXT X
I found this has to be the first set of statements after CASE @idcontrol
When I put it after the other button 'case' statements, it wouldn't work
*/