April 17, 2024, 06:27:34 PM

News:

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


Using a calendar control with edit command controls

Started by AdrianFox, January 10, 2011, 12:05:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

January 10, 2011, 12:05:26 PM Last Edit: January 10, 2011, 12:39:38 PM by AdrianFox
I wonder if anyone can tell what is going wrong here.

I am trying to use a calendar control to select a date which is then pasted at the beginning of existing text in an edit box.  In theory, having created a string from the calendar control (which works fine), I should be able to use the CONTROLCMD, @edcut, @edpaste commands to insert the date at the beginning and then to paste back the text at the cursor point.
When I try to do this in the code that follows, I get several copies of the date selected plus a spurious one.  This only happens when I use the controlcmd commands. Just using the calendar control works fine but using setcontroltext on its own will just replace the previous text of course.

Why is this happening, and what can I do to prevent this?
               CASE @IDCONTROL
'CALENDAR CONTROL HANDLING BELOW
if @controlid=diary_calendar1        'reads the calendar control and sets the date into verbose fashion and displays on screen when clicked
CONTROLCMD diary,diary_edit1,@EDSETSELECTION,0,-1                  ' select all existing displayed text in editbox
CONTROLCMD diary,diary_edit1, @EDCut                                         'should cut all the text and leave in memory
ccGetCurSel diary,diary_calendar1,m,d,y                                          'get the date selected
datenumber=str$(d)+str$(m)+str$(y)                                            
gosub monthdefine                                                                       'SUB creates proper name for each month.  
mydate=str$(d)+" "+month$+" "+str$(y)                                       'mydate is string with verbose date
setcontroltext diary,diary_EDIT1,mydate                                    'print the date in the edit box
setfocus diary,diary_edit1  'set focus on edit box                          'setfocus on edit box
CONTROLCMD diary,diary_edit1,@EDSETSELECTION,-3,-3              'this sets the cursor position at the end of the date string in the edit box
CONTROLCMD diary,diary_edit1, @EDpaste                                     'this pastes the text back at the insertion point but also results in multiple instances of date  


endif




Here's an example of the result:

"7 January  2011 7 January  2011 10 January  2011This was the original text in the edit box"

7th January was selected in the calendar control,  10 January has come from I know not where, and 'This was the original text in the edit box' was the text cut and pasted back.

Any ideas?

What I'd ideally like to do is select a date on the calendar control and paste it into my edit box at wherever I have placed the cursor.

Addendum:

Just tried working round the problem but still got these multiple entries..
[CASE @IDCONTROL
'CALENDAR CONTROL HANDLING BELOW
if @controlid=diary_calendar1  'reads the calendar control and sets the date into verbose fashion and displays on screen when clicked
ccGetCurSel diary,diary_calendar1,m,d,y
datenumber=str$(d)+str$(m)+str$(y)
gosub monthdefine  'SUB gives a name to each month.  Not so easy to do with days
mydate=str$(d)+" "+month$+" "+str$(y)
buffer=getcontroltext(diary,diary_edit1)
setcontroltext diary,diary_edit1,mydate+"\n"+buffer
endif

/code]

This produces the result:

" 12 January  2011
12 January  2011
10 January  2011
This is the first line of text"

Having selected the 12 Jan as date.  The current date seems to appear from somewhere even though it is not selected on the calendar.

Adrian Fox

LarryMc

1st, the multiple date entries

If you remember when implementing a button you have to use
if @notifycode=0
That's because the system sends multiple messages to controls during different phases of operation
In case of a button a notifycode of 0 equates to a single click.(if you wanted to you could change the 0 to the number for a doubleclick and the button would no longer respond to a single click.

I believe the same thing is going on when you pick a date.
You have no if @notifycode= statement so any notification will fire your little routine.

QuoteNotifications

MCN_GETDAYSTATE
Sent by a month calendar control to request information about how individual days should be displayed. This notification message is sent only by month calendar controls that use the MCS_DAYSTATE style, and it is sent in the form of a WM_NOTIFY message.

MCN_SELCHANGE
Sent by a month calendar control when the currently selected date or range of dates changes. This notification message is sent in the form of a WM_NOTIFY message.

MCN_SELECT
Sent by a month calendar control when the user makes an explicit date selection within a month calendar control. This notification is sent in the form of a WM_NOTIFY message.

NM_RELEASEDCAPTURE (monthcal)
Notifies a monthcal control's parent window that the control is releasing mouse capture. This notification is sent in the form of a WM_NOTIFY message.

CONST MCN_FIRST = (-750)
CONST MCN_LAST = (-759)
CONST MCN_GETDAYSTATE = (MCN_FIRST + 3)
CONST MCN_SELCHANGE = (MCN_FIRST + 1)
CONST MCN_SELECT = (MCN_FIRST + 4)

CONST NM_FIRST = 0
CONST NM_RELEASEDCAPTURE = (NM_FIRST-16)


I don't know which is the correct one to use in your case. I'd have to trial and error it.
But you should be able to eliminate the duplicates.

Now I'll look into the second part.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

CONTROLCMD window | dialog, ID, @RTREPLACESEL, text$
should put it at where ever the curser is located unless I'm having a senior moment.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

January 10, 2011, 01:36:50 PM #3 Last Edit: January 10, 2011, 03:09:40 PM by AdrianFox
Thanks Larry.  As usual you are able to get right to the heart of a problem and explain it.

That gives me plenty to trial and discover which option works.

Thanks,

Adrian

This seems to work.... not sure why, but it works!  Took my addled old brain some time to come up with how to do it!

              CASE @IDCONTROL
CONST MCN_SELECT = (MCN_FIRST + 4)  'should be defined somewhere else but here will do for the moment
if @controlid=diary_calendar1
if @notifycode=MCN_SELECT Then 
ccGetCurSel diary,diary_calendar1,m,d,y
gosub monthdefine  'SUB gives a name to each month.  Not so easy to do with days
        mydate=str$(d)+" "+month$+" "+str$(y)
CONTROLCMD diary, diary_edit1, @RTREPLACESEL, mydate  'this works fine to put text at cursor position
endif
endif



Thanks again, Larry, your help is always right on the ball!
Adrian Fox