Groups | Search | Server Info | Login | Register
Groups > comp.databases.filemaker > #3543
| From | Jack Nastyface <nowhere@noplace.com> |
|---|---|
| Organization | Earth |
| Message-ID | <0001HW.2DE5E40D017FFE57306CF638F@news.astraweb.com> (permalink) |
| Subject | Re: Script to Format Selaction in a Text Field |
| Newsgroups | comp.databases.filemaker |
| References | <0001HW.2DE5299B01544BBC309C3E38F@news.astraweb.com> <slrn103ao6r.4je.t-usenet@ID-685.user.individual.de> |
| Date | 2025-05-27 08:14 -0400 |
On May 27, 2025, Martin Τrautmann wrote (in article<slrn103ao6r.4je.t-usenet@ID-685.user.individual.de>): > On Mon, 26 May 2025 18:58:35 -0400, Jack Nastyface wrote: > > I want to color some text in a text field using a script but I can’t > > figure > > out a way to do it. There doesn’t seem to be an applicable script step. > > Any > > ideal? > > You want to select some part of the text only? [snip] Martin, thank you so much for your reply. I wasn’t sure anyone was still monitoring this group :) Yes, I want to only select a part of the text. While I was waiting for a reply, I asked chatGPT to write a script for me. The result does exactly what I wanted. However it had an “off by one” error in it. LOL Nice to know chatGPT makes those kind of errors too. Here is the script: > # Assumes the field is named "YourTextField" > # Make sure to enable "Select entire contents" is OFF in the field settings > # This only works if the field s active and the user has selected text > Set Variable [ $start ; Value: Get ( ActiveSelectionStart ) ] > Set Variable [ $size ;Value: Get ( ActiveSelectionSize ) ] > Set Variable [ $text ; Value: Get ( ActiveFieldContents ) ] > If [ $size> 0 ] > Set Variable [ $before ; Value: Middle ( $text ; 1 ; $start ) ] > Set Variable [ $selected ; Value: Middle ( $text ; $start + 1 ; $size ) ] > Set Variable [ $after ; Value: Middle ( $text ; $start + $size + 1 ; Length ( $text ) ) ] Set Variable [ $coloredText ; Value: $before& TextColor ( $selected ; RGB ( 255 ; 0 ; 0 ) ) & $after ] > Set Field [ YourTable::YourTextField ; $coloredText ] > Else > Show Custom Dialog [ "No Text Selected" ; "Please select some text in the field before running this script." ] > End If > Notes: Replace YourTable::YourTextField with the actual table and field name. > This script assumes the field is being edited when the script is triggered. > For rich text, this formatting will apply and be visible if the field supports styled text (e.g., a Text field on a layout). The “off by 1” error is in the first line which should read > Set Variable [ $start ; Value: Get ( ActiveSelectionStart ) -1 ] Jack
Back to comp.databases.filemaker | Previous | Next — Previous in thread | Next in thread | Find similar
Script to Format Selaction in a Text Field Jack Nastyface <nowhere@noplace.com> - 2025-05-26 18:58 -0400
Re: Script to Format Selaction in a Text Field Martin Τrautmann <t-usenet@gmx.net> - 2025-05-27 08:51 +0200
Re: Script to Format Selaction in a Text Field Jack Nastyface <nowhere@noplace.com> - 2025-05-27 08:14 -0400
Re: Script to Format Selaction in a Text Field Martin Τrautmann <t-usenet@gmx.net> - 2025-05-27 15:30 +0200
csiph-web