Check User has not entered duplicate data

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tlottrike
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 11
Joined: Mon Oct 31, 2011 3:46 pm
Location: Edinburgh, Scotland
Contact:

Check User has not entered duplicate data

Post by tlottrike » Mon Jan 07, 2019 1:32 pm

Happy New Year all,

I have a Field I want the user to enter a unique Project code reference eg. "GFB". Sometimes the Project code reference can be very similar eg. "GFR" so I want to ensure the user doesn't duplicate a reference as the Project Code must be unique.

So I tried doing the following...

Code: Select all

on keyDown 
   if field me = me Then 
      Beep
   else
      pass keydown
   end if
end keyDown 
But Livecode is not liking it. So I have rummaged in my Livecode Lessons Books but so far I haven't seen anything that covers what I'm trying to do. However I am thinking there maybe a way of doing it using the example shown here http://lessons.livecode.com/m/2592/l/12 ... ce-of-text but it does seem a bit complicated (well to me it does) :)
IMac MacOSX 10.13
Livecode 9.0.0 Build 15103

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

Re: Check User has not entered duplicate data

Post by dunbarx » Mon Jan 07, 2019 3:16 pm

Hi.

I would do this a different way. Try this: make a button, name it "Product Code", and put this into its script:

Code: Select all

on mouseUp
   ask "Enter Project Code"
   if it is not among the lines of the productCodes of me then
      set the productCodes of me to the productCodes of me & return & it
      --doSomethingUsefulWithTheNewCode
   else
      answer "Code already exists!"
   end if
end mouseUp
Every time you click on it, you can enter a code. If it is new, it is added to the list of codes, held in a custom property of the button itself. If it already exists, it complains, and does nothing. You can always check the entirety of the custom prop by just asking for it:

Code: Select all

put the productCodes of button "Product Code" into someVariable
But if it is a new code, you can use that overLong command call to do your thing.

Craig Newman

tlottrike
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 11
Joined: Mon Oct 31, 2011 3:46 pm
Location: Edinburgh, Scotland
Contact:

Re: Check User has not entered duplicate data

Post by tlottrike » Mon Jan 07, 2019 3:29 pm

Ah I like it, I shall give that a spin.

Thanks
IMac MacOSX 10.13
Livecode 9.0.0 Build 15103

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”