Inserting a character at the text insertion point in a field

Tore Nilsen tore.nilsen at me.com
Tue Apr 28 15:23:23 EDT 2015


Thank you!
It did the trick nicely. Sometimes the solution is just too easy! In Norway comma is used as a decimal sign, and this way my students can make a script that will allow the user to write whatever decimal sign they choose. 


Tore


> 28. apr. 2015 kl. 21.17 skrev Peter Haworth <pete at lcsql.com>:
> 
> Hi Tore,
> You'll need to to use the selectedChunk property of the field. Check out
> the dictionary entry for it but as long as no text is selected in the
> field, replace your put statement with:
> 
> put word 4 of the selectedChunk of me into tPos
> put "." after char tPos of me
> 
> 
> Pete
> lcSQL Software <http://www.lcsql.com>
> Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
> SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>
> 
> On Tue, Apr 28, 2015 at 12:06 PM, Tore Nilsen <tore.nilsen at me.com> wrote:
> 
>> I try to make a script in a field to allow only numbers or the decimal
>> sign to be entered into the field. To block any other key is easy, but I
>> have run into problems when I try to insert the decimal sign at the text
>> insertion point in the field.
>> 
>> This script only allows me to insert the decimal sign at the end of the
>> string. I seem to be unable to find any help in the lessons on the runner
>> web site or in the dictionary.  Does anyone have a smart solution that I
>> can use to impress my students, and maybe help them in their preparations
>> for their exam?
>> 
>> on keyDown theKey
>>      if theKey is a number then
>>      pass keyDown
>> end if
>>   if theKey is "." or theKey is "," then
>>      if the text of me is not empty and "." is not in me then
>>         put "." after me
>>      end if
>>   end if
>> end keyDown
>> 
>>>> 
>> Tore Nilsen
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list