Detecting and Setting Insertion Point in a field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Curmudgeon
Posts: 3
Joined: Sat Jan 09, 2010 4:28 pm

Detecting and Setting Insertion Point in a field

Post by Curmudgeon » Sat Jan 09, 2010 4:46 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Detecting and Setting Insertion Point in a field

Post by Mark » Sat Jan 09, 2010 6:26 pm

Dear Curmudgeon,

Try the following:

Code: Select all

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

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Curmudgeon
Posts: 3
Joined: Sat Jan 09, 2010 4:28 pm

Re: Detecting and Setting Insertion Point in a field

Post by Curmudgeon » Sat Jan 09, 2010 7:06 pm

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.

Curmudgeon
Posts: 3
Joined: Sat Jan 09, 2010 4:28 pm

Re: Detecting and Setting Insertion Point in a field

Post by Curmudgeon » Sat Jan 09, 2010 7:46 pm

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?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Detecting and Setting Insertion Point in a field

Post by Mark » Sat Jan 09, 2010 10:23 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”