mrmogway Posted October 28, 2016 Share Posted October 28, 2016 I'm trying to allow users to create chemical formulas in a text field. An example; (NH4)2C2O4 whereas all the numbers are subscript. For now a user would type the letters and when a subscripted number is needed they would click (a script) that would paste what is needed. All is good to that point. The problem I'm having is how to finish writing the script. I can't figure out how to: a. return to normal text and b. keep the cursor at the end (no spaces) of the text in that field. I'm close. Any help would be appreciated. Link to comment Share on other sites More sharing options...
doughemi Posted October 28, 2016 Share Posted October 28, 2016 (edited) Try this script: Set Variable [$text; Value:WordCount ( yourTable::YourTextField )] Set Variable [$theForm; Value:RightWords ( yourTable::YourTextField ; 1 )] Set Variable [$len; Value:Length($theForm)] Set Variable [$pointer; Value:1] Commit Records/Requests [No dialog] Loop Set Variable [$char; Value:Middle($theForm; $pointer;1)] If [not IsEmpty ( Filter ( $char; "123456789" ) )] Set Variable [$char; Value:TextStyleAdd($char; 8)] Else Set Variable [$char; Value:Upper($char)] End If Set Variable [$converted; Value:$converted & $char] Set Variable [$pointer; Value:$pointer + 1] Exit Loop If [$pointer > $len] End Loop Set Field [yourTable::YourTextField; LeftWords ( yourTable::YourTextField; $text - 1 ) &" " & $converted] Set Selection [yourTable::YourTextField; Start Position: Length ( yourTable::YourTextField ) + 1; End Position: Length ( yourTable::YourTextField )] # The script will convert lower-case letters to upper case as well, so the user can type c2h5oh and the script will format it correctly. If you move the script to one of the first 10 positions in the script list, the user can type the position number while holding the Command key (Mac)or Ctrl key (Windows) to execute it. It must be executed immediately after typing in the formula. EDIT: This script fails with the introduction of parentheses in the formula. I don't have time now, but will revise it this evening. Edited October 28, 2016 by doughemi error in script Link to comment Share on other sites More sharing options...
doughemi Posted October 28, 2016 Share Posted October 28, 2016 Do parentheses occur anywhere other than the beginning of a formula? Are there more than one set of parenrheses in a formula? Link to comment Share on other sites More sharing options...
Recommended Posts