Check if text in field already existsalready exists

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
CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Check if text in field already existsalready exists

Post by CAsba » Mon Mar 06, 2023 8:33 pm

Hi,
I've made a function that makes a code from the initials of a customer name. The code is put into a field called 'newcode' and is later used as the index of the customer line in a database. How can it be scripted to check if the code made already exists, and if it does, to suffix this latest instance of it incrementally (by 1) to distinguish it from one or more previous similar codes? I've tried using the 'exists' and 'there is ' functions without success or any idea of the syntax for this context.

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

Re: Check if text in field already existsalready exists

Post by dunbarx » Mon Mar 06, 2023 11:06 pm

CAsba.

Is there only a single field where all these new codes are stored? If so, just (pseudo):

Code: Select all

if yourNewCode is not in fld "newCode" then loadNewCode
There are other, similar variants, such as. (pseudo):

Code: Select all

if yourNewCode is not among the words in fld "newCode" then loadNewCode
Craig

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

Re: Check if text in field already existsalready exists

Post by dunbarx » Mon Mar 06, 2023 11:09 pm

Rereading, in order to help you with the second part of your question, how to modify a new code where a copy already exists, tell me how the codes are entered into the field. One per line, for example?

In this way we can construct the currently non-existent handler "loadnewCode" so that it does the work in either situation.

Craig

CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Re: Check if text in field already existsalready exists

Post by CAsba » Wed Mar 08, 2023 11:59 am

Hi Craig,
I wonder, is it possible to check if the text in field newcode is already being used in a datagrid, relating to another customer with the same initials on which the customer code is based . (The text in field newcode will be entered into the datagrid, but cannot be the same as another datagrid entry.)

CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Re: Check if text in field already existsalready exists

Post by CAsba » Wed Mar 08, 2023 12:46 pm

Hi again, Craig,
Ignore my last, I got it working via a field as you suggested.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”