Page 1 of 1

Check User has not entered duplicate data

Posted: Mon Jan 07, 2019 1:32 pm
by tlottrike
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) :)

Re: Check User has not entered duplicate data

Posted: Mon Jan 07, 2019 3:16 pm
by dunbarx
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

Re: Check User has not entered duplicate data

Posted: Mon Jan 07, 2019 3:29 pm
by tlottrike
Ah I like it, I shall give that a spin.

Thanks