May 10, 2024, 04:50:32 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Editbox Woes

Started by jay, September 26, 2007, 06:17:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jay

Why doesn't this code work  ???


CONST EDIT_1 = 1
CONST EDIT_2 = 2
CONST STATIC_3 = 3

DEF InFocus:INT

DIALOG d1
CREATEDIALOG d1,0,0,300,136,0x80C80080,0,"Test Enter On Edit Boxes",&d1_handler
CONTROL d1,@EDIT,"Edit1",50,39,200,18,0x50810000,1
CONTROL d1,@EDIT,"Edit2",50,78,200,18,0x50810000,2
CONTROL d1,@STATIC,"Just Hit the Enter Key",50,26,194,14,0x5000010B,3


run = 1
SHOWDIALOG d1

'process messages until run = 0
WAITUNTIL run = 0
run = 0
CLOSEDIALOG d1

END


SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
SETCONTROLTEXT d1, EDIT_1, ""
SETCONTROLTEXT d1, EDIT_2, ""
CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_1
/* respond to edit notifications here */
InFocus = 1
IF @NOTIFYCODE = 0
IF GETKEYSTATE(0x0D):'Hit Enter Key
GOSUB Message
ENDIF
ENDIF

CASE EDIT_2
/* respond to edit notifications here */
InFocus = 2
IF @NOTIFYCODE = 0
IF GETKEYSTATE(0x0D):'Hit Enter Key
GOSUB Message
ENDIF
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB




SUB Message
SELECT InFocus
CASE 1
MESSAGEBOX(d1,"This is message ONE", "Message One")
CASE 2
MESSAGEBOX(d1,"This is message TWO", "Message Two")
DEFAULT
MESSAGEBOX(d1,"Error DEFAULT", "ERROR Default")
ENDSELECT
ENDSUB





The variable InFocus does not change to the number 2 in order to use the Select Case in the subroutine Message.
If you comment out all the code in EDIT_2 the program still does the same thing.
All I get is Case 1 being selected.
Help....   Thanks...

Ionic Wind Support Team

OK You are mixing up messages and hardware.  GETKEYSTATE is for reading the keyboard directly, not in response to an edit control message, and has nothing to do with the text of the control.  It reads the keyboard at the time of the call so if you aren't holding down the button it would return false.

In any event an edit control has many notification codes,  testing for 0 isn't doing you much good and I am assuming you copied that from a button handler somewhere.  You could look for @ENCHANGE which tells you when the text of the control was changed, but that won't get you the return key unless it is a multiline edit control.  Luckily there is a command to help you. 

See: SETCONTROLNOTIFY in the users guide.  Here is an example of it's usage:


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
SETFONT win,"Ariel",9,400,0,5
SETCONTROLNOTIFY(win,5,1,1)
SetFocus win,5
WAITUNTIL win=0
END

SUB handler
SELECT @MESSAGE
CASE @IDCONTROL
IF @CONTROLID = 5
SELECT @NOTIFYCODE
CASE @ENENTERKEY
MESSAGEBOX win,GetControlText(win,5),"Enter Pressed!"
SetFocus win,5
CASE @ENTABKEY
MESSAGEBOX win,"Tab key pressed","Info"
SetFocus win,5
ENDSELECT
ENDIF
CASE @IDCREATE
CENTERWINDOW win
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
ENDSELECT
RETURN
ENDSUB


Ionic Wind Support Team

GWS

Hmm .. SETCONTROLNOTIFY, @ENENTERKEY ... we haven't got that in CBasic ..  ::)

Graham
Tomorrow may be too late ..

Ionic Wind Support Team

This was an Emergence question Graham  ;)
Ionic Wind Support Team

jay

Thanks for the quick response.   :)

Hi Paul,

I have looked at SETCONTROLNOTIFY under the examples and I must be doing something wrong when it comes to coding this.  I did notice that
you are using a window and I am using a dialog but really that should not make a difference.

I am posting this code here that I have tried to write and it has the SETCONTROLNOTIFY at the top of the program just like the example provided
in EBASIC.  I have tried to mimic it as close as possible with no good results.  I am also in a hurry.  Sorry about.


CONST EDIT_1 = 1
CONST EDIT_2 = 2
CONST STATIC_3 = 3
DIALOG d1
CREATEDIALOG d1,0,0,300,136,0x80C80080,0,"Test Enter On Edit Boxes",&d1_handler
CONTROL d1,@EDIT,"Edit1",50,39,200,18,0x50810000,EDIT_1
CONTROL d1,@EDIT,"Edit2",50,78,200,18,0x50810000,EDIT_2
CONTROL d1,@STATIC,"Type In Editboxes then hit enter",50,26,194,14,0x5000010B,STATIC_3


run = 1
SHOWDIALOG d1

'process messages until run = 0
WAITUNTIL run = 0
'Set tab to false and return to true
SETCONTROLNOTIFY(d1,EDIT_1,0,1)
SETCONTROLNOTIFY(d1,EDIT_2,0,1)
run = 0
CLOSEDIALOG d1

END




SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
SETCONTROLTEXT d1, EDIT_1, ""
SETCONTROLTEXT d1, EDIT_2, ""
CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_1
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENENTERKEY
GOSUB MessageOne
SetFocus d1,EDIT_1
ENDSELECT
'IF @NOTIFYCODE = @ENENTERKEY
'GOSUB MessageOne
'ENDIF
CASE EDIT_2
/* respond to edit notifications here */
IF @NOTIFYCODE = @ENENTERKEY
GOSUB MessageTwo
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB



SUB MessageOne
MESSAGEBOX(d1,"This is message ONE", "Message One")
ENDSUB

SUB MessageTwo
MESSAGEBOX(d1,"This is message Two", "Message Two")
ENDSUB


I am doing my best to try to follow the manual provided but I must be missing something.    :-\
I will play with it some more throughout the day
Would really like some more input.  ;)   Thanks for your help. :)

Ionic Wind Support Team

Your SETCONTROLNOTIFY statements aren't executed until after the dialog closes (loop ends).  However it doesn't matter since a dialog processes messages differently.  The users guide mentions that SETCONTROLNOTIFY only works with controls created in a regular window.

Windows (the OS itself) traps certain keyboard messages for dialogs including the TAB, enter, and ESC keys.  The enter key is used to press the default button of a dialog, usually an OK button.  The TAB key is used to cycle between controls, and the ESC key is used to press the CANCEL button, it sends your handler the control ID of 2.

If you explain what you are trying to accomplish I can guide you further. 
   
Paul.

Ionic Wind Support Team

jay

Hey Paul,

Couldn't get back sooner to you; had to go to work.

What I have is two editboxes let's call EDIT_1 and EDIT_2.  EDIT_1 has a word in it that is in spanish  and edit_2 has the definition.
I am writing a verb translation program for spanish and these two edit boxes of course are
going to be my input and output for the program.

I want to bypass  the default "push button" technique and use the "Enter Key" technique to send out a message to update a
file if a new verb is found that was not previously defined.

What happens right now is I type in a spanish verb in  EDIT_1 (let's say dejar) and I hit enter.  The definition of the
verb pops up in edit_2  (let's say to leave) so now I have both  EDIT_1  and  EDIT_2  with some text
in it.  I have "dejar"  (day har) in  EDIT_1 and the definition "to leave" in  EDIT_2 .  I hit a button and that button
command will conjugate the verb in  EDIT_1  putting it in its proper tense i.e future, past, present, imperfect, etc.

Now if a verb is not found in the list,   EDIT_2  will display "no translation found" instead of the meaning of the verb.
Another button called "add to list" is then enabled so the user clicks that and edit_2
now displays the word "to " and the caret is moved to the end of the word "to" with a space added also. 
The user can then type in the definition and this is where the enter key comes into play.
I am using the enter key to update the file along with a warning stating that the files will be updated proceed yes or no.

Everything works right up to the point of the "Enter Key" in  EDIT_2 .  This is where I am stuck and I cannot get the
"Enter Key" to work properly.

My first conjugation program for spanish works like a charm but I wanted to add more features to the gui end of it. 
I rewrote alot of it and after some careful planning and decisions I came up with the conclusion that this is the road I want to take
to expand the program.

The "Enter Key" is part of the new feature instead of maybe another dialog opening up and the user can update from
there. The open dialog box is what I have in the old program. I do not wish to add a dialog to this program.

The Enter Key seems to be wrapped into  EDIT_1 even though EDIT_2 has focus. 
I have come up with a "band aid" solution using a boolean value that tells me if  EDIT_1 or EDIT_2 is or has
focus but that leads to other problems that I want to add like "What happens when the user hits the delete key"
I want that to erase all of the editboxes that have been used and reset some radio buttons. 
This also leads to "Hack and Slash" programs that are hard to interpret and that is the last thing I want. 
I am trying to keep the code clean

At this point I think you might need an actual picture of the working program.

Here is some code I made up earlier today


CONST EDIT_1 = 1
CONST EDIT_2 = 2
CONST STATIC_3 = 3
CONST BUTTON_4 = 4

DEF choice, update:INT

DIALOG d1

CREATEDIALOG d1,0,0,300,156,0x80C80080,0,"Test Enter On Edit Boxes",&d1_handler
CONTROL d1,@EDIT,"Edit1",50,39,200,18,0x50810000,EDIT_1
CONTROL d1,@EDIT,"Edit2",50,78,200,18,0x50810000,EDIT_2
CONTROL d1,@STATIC,"Enter a Spanish Verb",50,26,194,14,0x5000010B,STATIC_3
CONTROL d1,@BUTTON,"Update Files",97,112,106,20,0x50010000,BUTTON_4


run = 1
SHOWDIALOG d1

'process messages until run = 0
WAITUNTIL run = 0

'Set tab to false and return to true
'SETCONTROLNOTIFY(d1,EDIT_1,0,1)
'SETCONTROLNOTIFY(d1,EDIT_2,0,1)
run = 0
CLOSEDIALOG d1

END




SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
SETCONTROLTEXT d1, EDIT_1, "dejar      (day har)"
SETCONTROLTEXT d1, EDIT_2, "No Definition Found."

'SETCONTROLNOTIFY(d1,EDIT_1,0,1)
'SETCONTROLNOTIFY(d1,EDIT_2,0,1)
CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG d1,@IDOK

CASE @IDCONTROL
SELECT @CONTROLID

CASE EDIT_1
/* respond to edit notifications here */
SELECT @NOTIFYCODE:'I know don't use this-it keeps messageboxes from showing
                                   'up more than once when issued at the right call.
CASE 0
'Place If statements in proper order otherwise weird results happen
IF GETKEYSTATE(0x0D) AND choice = 2 AND update = 1:'Enter Key Pressed
GOSUB AreYouSure
ENDIF

IF GETKEYSTATE(0x0D) AND choice = 2:'Enter Key Pressed
GOSUB MessageTwo
ENDIF

IF GETKEYSTATE(0x0D) AND choice = 1:'Enter Key Pressed
GOSUB MessageOne
ENDIF

ENDSELECT
choice = 1:'Still Need an if statement to see if EDIT_2 has focus before we update choice

CASE EDIT_2
/* respond to edit notifications here */
/*Why does all of the code end up in CASE EDIT_1 in order to work right?
  It is like EDIT_2 only reads the first posible choice before exiting*/
choice = 2
SELECT @NOTIFYCODE
CASE 0
ENDSELECT

CASE BUTTON_4
IF @NOTIFYCODE = 0
/*button clicked*/
update = 1
SETFOCUS d1, EDIT_2
SETCONTROLTEXT d1, EDIT_2, "to "
CONTROLCMD d1, EDIT_2, @EDSETSELECTION, 3, -1
ENDIF
ENDSELECT

ENDSELECT

RETURN
ENDSUB







'Dummy subroutine
SUB MessageOne
MESSAGEBOX(d1,"This is message ONE", "Message One")
ENDSUB

'Dummy subroutine
SUB MessageTwo
MESSAGEBOX(d1,"This is message Two", "Message Two")
ENDSUB

SUB AreYouSure
IF MESSAGEBOX(d1,"This will update the files.  Proceed?", "File Update",@IDOK) = 1
MESSAGEBOX(d1,"Files Updated", "File Update Complete"):'User Information needed
ENABLECONTROL d1,Button_4, 0: 'Disable Update Files button
SETFOCUS d1, EDIT_1: 'Give EDIT_1 focus
choice = 1: 'EDIT_1 will have focus
update = 0: 'FALSE we are no longer updating
ELSE
SETCONTROLTEXT d1, EDIT_2, "to ": 'Setup EDIT_2
SETFOCUS d1,EDIT_2:'Give EDIT_2 Focus
CONTROLCMD d1, EDIT_2, @EDSETSELECTION, 3, -1: 'Put Cursor in proper place
ENABLECONTROL d1,Button_4, 1:'Make sure Update Files is enabled
choice = 2: 'Set for proper EDIT box.  Focus is give to EDIT_2
update = 1: 'TRUE we are still updating
ENDIF
ENDSUB




Hope this helps and thank you   :)

jay

Hi everyone,

Thought I would post this to explain that I have found a solution to my problem.


I have been researching some more on this problem with the EDIT_1 and EDIT_2 boxes and I think
I have finally found a solution that is up to EBasic Coding Standards.
Since my last post you will remember that I had problems with the enter key and the delete key
being used while an edit box had focused. I couldn't get them to be independent of eachother calling different
subroutines.  The way they were written or coded was also wrong.
Please refer to the examples I posted earlier and you will see what I mean.

This new example comes from other examples that I have researched on the forum and from a
database program called addressbook in the projects folder.

In this program you will notice that each editbox is independant (meaning they call different subroutines) of the other
and it can be achieved by using the SETTIMER method.  I use it to send an @IDTIMER message much like the one in the
addressbook example.  I had a problem in the previous programs and both editboxes did not
function correctly; they did not call independent subroutines.  Long story short here is what I did...

The @IDTimer is checked every 1/8 of a second for keyboard input. It sends a message to
the @IDKEYDOWN that belongs to the dialog form itself not the editbox.
@IDKEYDOWN takes it from there and process the messages I have depending on which editbox
has focus and if none of them have focus well nothing will happen.  It also knows which key
I want to fully process.


Here is the code



CONST EDIT_1 = 1
CONST EDIT_2 = 2
CONST STATIC_3 = 3
CONST BUTTON_4 = 4

DEF Infocus:INT

DIALOG d1

CREATEDIALOG d1,0,0,300,156,0x80C80080,0,"Test Enter and Delete On Two Edit Boxes",&d1_handler
CONTROL d1,@EDIT,"Edit1",50,39,200,18,0x50810000,EDIT_1
CONTROL d1,@EDIT,"Edit2",50,78,200,18,0x50810000,EDIT_2
CONTROL d1,@STATIC,"Enter a Spanish Verb",50,26,194,14,0x5000010B,STATIC_3
CONTROL d1,@BUTTON,"Update Files",97,112,106,20,0x50010000,BUTTON_4

run = 1
SHOWDIALOG d1

'process messages until run = 0
WAITUNTIL run = 0

CLOSEDIALOG d1

END




SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
Infocus = 0
SETCONTROLTEXT d1, EDIT_1, "Hit delete or enter key"
SETCONTROLTEXT d1, EDIT_2, "Boxes are now independant"
SETCONTROLNOTIFY(d1,EDIT_1,0,1)
SETCONTROLNOTIFY(d1,EDIT_2,0,1)
STARTTIMER d1,125:'Check every 1/8 second

CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG d1,@IDOK

CASE @IDKEYDOWN
IF GETKEYSTATE(0x2E) AND Infocus = 1
'Process your events
MESSAGEBOX d1, "Delete Key Pressed - 1", "Delete Key Pressed - 1"
ENDIF

IF GETKEYSTATE(0x2E) AND Infocus = 2
'Process your events
MESSAGEBOX d1, "Delete Key Pressed - 2", "Delete Key Pressed - 2"
ENDIF

IF GETKEYSTATE(0x0D) AND Infocus = 2
'Process your events
MESSAGEBOX d1, "Enter Key Pressed - 2", "Enter Key Pressed -2"
ENDIF

IF GETKEYSTATE(0x0D) AND Infocus = 1
'Process your events
MESSAGEBOX d1, "Enter Key Pressed - 1", "Enter Key Pressed - 1"
ENDIF

CASE @IDTIMER
SENDMESSAGE (d1 , @IDKEYDOWN, @WPARAM, @LPARAM)

CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_1
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENSETFOCUS
Infocus = 1
CASE @ENKILLFOCUS
Infocus = 0
ENDSELECT
CASE EDIT_2
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENSETFOCUS
Infocus = 2
CASE @ENKILLFOCUS
Infocus = 0
ENDSELECT
CASE BUTTON_4
IF @NOTIFYCODE = 0
/*button clicked*/
SETFOCUS d1, EDIT_2
SETCONTROLTEXT d1, EDIT_2, "to "
CONTROLCMD d1, EDIT_2, @EDSETSELECTION, 3, -1
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB






There is one problem that can occur and it would happen if you hit the enter or delete key before the starttimer method checked for keyboard input.
I found myself hitting delete and or enter a couple of times in order to call the correct function. 
To fix this I lowered the seconds being processed to 64 instead of 125 of a second.

The only thing I question is

1.) Do I need a STOPTIMER command somewhere in this program after the program is terminated?
   the addressbook did not have one that I could find.

Let me know what you think.   :)