Page 1 of 1

Detecting and Setting Insertion Point in a field

Posted: Sat Jan 09, 2010 4:46 pm
by Curmudgeon
I am writing a script for a text field which will be completely editable, ie. a Journal Entry. I want to insert a Date-Time Stamp where ever the current insert point might be. It may not be at the end of the field, so
"Put the date & " " & the time after field 1" will not always work

Here is how I am trying to do it:

On returninfield
if the controlKey is down then
-- get the insertion point of this field
-- put the date & time into char it of this field
-- set the insertion point after this field
end if
pass returninfield
end returninfield


Thanks for your help.

Re: Detecting and Setting Insertion Point in a field

Posted: Sat Jan 09, 2010 6:26 pm
by Mark
Dear Curmudgeon,

Try the following:

Code: Select all

put the short date & comma && the short time after the selectedchunk
Best,

Mark

Re: Detecting and Setting Insertion Point in a field

Posted: Sat Jan 09, 2010 7:06 pm
by Curmudgeon
Okay, that helps some, The first part works; The date and time are inserted at the proper place.

Now the focus is set to the next field. Apparently under normal conditions [Cntrl - Enter] tabs to the next field.

Is there another handler that I need to intercept to prevent this from happening? I want to use the [Cntrl - Enter] combination simply because I have another application that I have used for years that inserts the Date-Time with [Cntrl - Enter], and old habits are hard to break.

Re: Detecting and Setting Insertion Point in a field

Posted: Sat Jan 09, 2010 7:46 pm
by Curmudgeon
Never mind!
I figured it out. I need to put the "pass returninfield" into an else statement.

on returninfield
if the controlKey is down then
put the seconds into dater
convert dater to dateitems
put item 2 of dater & "/" & item 3 of dater & "/" & item 1 of dater & " " & item 4 of dater & ":" & item 5 of dater & return after the selectedchunk
select after the last word of field "Notes"
else
pass returninfield
end if

end returninfield


BTW; How do you get the "Code: Select all" box to display the code?

Re: Detecting and Setting Insertion Point in a field

Posted: Sat Jan 09, 2010 10:23 pm
by Mark
Hi Curmudgeon,

Write a script, select the text and click on the Code button just above the text field in which you're writing. This puts code tags around your script. You can also type the code tags manually.

Best,

Mark