On Tue, 27 May 2025 08:14:05 -0400, Jack Nastyface wrote:
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:
Nevertheless good to know that chatGPT does some decent work
# 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 ) ]
well chosen and documented
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 ]
Here's a certain weakness since it does work on a certain field only.
The approach which I suggested would work on any field you are currently
in. But you could script to set the active field name for another
variable and select the field then again.
Else
Show Custom Dialog [ "No Text Selected" ; "Please select some text in the field before running this script." ]
End If
One of the options. Instead you might use a dialog to cancel or do the operation on the full text instead.
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 ]
a typical and minor mistake, solved easily by debugging. You now might google some of the script steps whether this good solution had been written by
someone else before. Obviously, this solution here does apply colors
only, while there are other formatting options, too.
So thanks for the chatGPT hint - this might simplify future script
editing if you can copy/paste those scripts directly.
How well does it work if you tell chatGPT to translate that script for
German language setup? :-)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)