Inserting date in text

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Inserting date in text

Post by urbaud » Thu Apr 16, 2009 5:26 am

I have a multiline text field called “text1â€
urbaud

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Inserting date in text

Post by sturgis » Thu Apr 16, 2009 5:42 am

Probably the easiest way to do this would be to have a placeholder string in your field where you want to insert the date, and use replace.

So if your field has
I would like the _date_ text to have several dates _date_ dispersed throughout _date_ the text like this

then you can use code like this to do what you want.

Code: Select all

on mouseUp
   put the long date into theDate
   replace "_date_" with theDate in field "field"
end mouseUp
The keyword "into" always behaves the way you described. Whatever is there now goes away and is replaced what you're putting "into" the container. YOu can use alternate keywords for different affects like after will append your new string at the end, before inserts it at the start..

[quote="urbaud"]I have a multiline text field called “text1â€

Tim
Posts: 29
Joined: Wed Oct 31, 2007 12:56 pm

Post by Tim » Thu Apr 16, 2009 1:21 pm

The best way is to use the "merge" command and have the rev date command in double square brackets - [[ ]]

Here is an example:

put "The day today is [[the long date]]" into tVar
put merge(tVar)

Will output :

"The day today is Thursday, April 16, 2009"

You can use any Rev command inside the [[ ]] and can have as many instances of [[ ]] as you like in the string ... see the dictionary entry for the "merge" command for more information.

Best,

Tim.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Thu Apr 16, 2009 3:46 pm

Oh cool, thanks from me too!
Tim wrote:The best way is to use the "merge" command and have the rev date command in double square brackets - [[ ]]

Here is an example:

put "The day today is [[the long date]]" into tVar
put merge(tVar)

Will output :

"The day today is Thursday, April 16, 2009"

You can use any Rev command inside the [[ ]] and can have as many instances of [[ ]] as you like in the string ... see the dictionary entry for the "merge" command for more information.

Best,

Tim.

urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Post by urbaud » Fri Apr 17, 2009 12:09 am

Sturgis and Tim, thanks so much for your suggestions. Now that I see the code, is there a way to insert the date where the cursor is? I'd like to try to get away without using a placeholder, just the cursor. Any more help is much appreciated.

Thanks,
urbaud
urbaud

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Fri Apr 17, 2009 12:49 am

Try this

Code: Select all

  put the long date into the selection

urbaud wrote:Sturgis and Tim, thanks so much for your suggestions. Now that I see the code, is there a way to insert the date where the cursor is? I'd like to try to get away without using a placeholder, just the cursor. Any more help is much appreciated.

Thanks,
urbaud

urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Post by urbaud » Fri Apr 17, 2009 9:43 pm

Hi sturgis,

Thanks so much for the one liner. It works exactly as I wanted. thanks again.

urbaue
urbaud

Post Reply