Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!ncar!gatech!purdue!haven!mimsy!tove.cs.umd.edu!potter From: potter@tove.cs.umd.edu (Richard Potter) Newsgroups: comp.sys.mac.hypercard Subject: The cleanest way to index into fields w/ text cursor? Summary: Is there a better way to write this code? Keywords: ugly code Message-ID: <29617@mimsy.umd.edu> Date: 28 Jan 91 20:24:22 GMT References: <2373@beguine.UUCP> Sender: news@mimsy.umd.edu Reply-To: potter@tove.cs.umd.edu (Richard Potter) Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 42 subject: the cleanest way to index into fields w/ text cursor What is the best way to get the location of the text cursor in a field? What is the best way to use a variable to index into a field? Background: I needed a HyperCard script to delete characters before the cursor back to but not including the first non-blank character. After browsing through the HyperTalk manual this is what I came up with. on functionKey fkeyv if fkeyv=5 then put the selectedchunk into cursorloc put (word 5 to 8 of cursorloc) into thefield put (word 2 of cursorloc) into cursorindex put (cursorindex-1) into cursorindex repeat while " " = (the value of ("char " & cursorindex & thefield)) do "put " & quote & quote & " into " & "char " & cursorindex & thefield put (cursorindex-1) into cursorindex end repeat end if end functionKey This script goes in the stack script. You click the cursor in any field and press F5 to start the script. I am using HyperCard Version 1.2. This script works, but I am wondering if there is a more direct way of doing this. This is my first script that manipulates fields. In particular, the line: put the selectedchunk into cursorloc seems a cludgy way to get the location of the cursor. Also, the line: do "put " & quote & quote & " into " & "char " & cursorindex & thefield seems a very hard way just to delete the character at the position designated by 'cursorindex'. Is there a way to avoid using 'do'? thanks in advance, --Richard