cursor position before decimal or after

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

cursor position before decimal or after

Post by jalz » Sun Mar 01, 2015 12:29 am

Hi Guys,
I've been using this code below to enter in numeric values with a decimal. This seems to work fine, however, when there are 2 decimals in the field I want to continue to allow the entry of these valid characters if the cursor is before the decimal place with two digits. I therefore need to change this line of code "if length (item 2 of me) = 2 then exit keyDown" to detect the cursor position, and pass KeyDown if the number being keyed in is before the decimal with two digits. Can someone help me with the relevant code. I thought I could get cursor/caret position and then compare it with where the decimal, pass keydown if its before else exit keydown, but cant fund the commands i need in the dictionary.

Code: Select all

on keydown tKey
   if tKey is in "-1234567890." then
      if "." is in me then
         if tKey is "." then
            answer "You cannot have more than 1 decimal in this field"
            exit keyDown
         else
            set the itemDelimiter to "."
            if length (item 2 of me) = 2 then exit keyDown
            pass keyDown
         end if
      end if
      pass keyDown
   end if
end keydown

Thanks
Jalz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6614
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: cursor position before decimal or after

Post by dunbarx » Sun Mar 01, 2015 6:02 am

Hi.

I just bet that if you looked up the "selectedChunk" in the dictionary, you would be running for your keyboard.

Craig

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: cursor position before decimal or after

Post by jalz » Sun Mar 01, 2015 10:11 am

Thanks Craig - I missed that one. All sorted now :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”