Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) Read Only AND Unique? (Read 6173 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Read Only AND Unique?
Aug 8th, 2007 at 7:19pm
Print Post Print Post  
In my personnel database I have an element, FullName, which contains the combined strings of FirstName and Lastname.  I want this element to be not-gray read-only (it is filled by programming).  Of course, I also want it to be unique, so that both Stef and Michelle don't try to add the same new hire when he comes on board.

"Unique" is one of the selections of the Read-Only property selector.  However, it renders the element writable.  If I then use programming to make it read-only, i.e. ReadOnly(Fullname,2), I then no longer get warnings of non-unique values.

Is there some way these two attributes can live together in harmony?
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read Only AND Unique?
Reply #1 - Aug 8th, 2007 at 8:00pm
Print Post Print Post  
Since you are setting the value in programming, you should also check it for uniqueness in your code. This allows you some control over what to do if it is not unique. Since you are setting the value in code and the user can't change it, giving the user a message that it is not unique isn't much good, since they can't actually do anything about it.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #2 - Aug 8th, 2007 at 8:12pm
Print Post Print Post  
I see what you are saying, but I'm not sure how to go about checking uniqueness in code.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read Only AND Unique?
Reply #3 - Aug 8th, 2007 at 8:21pm
Print Post Print Post  
Infinity wrote on Aug 8th, 2007 at 8:12pm:
I see what you are saying, but I'm not sure how to go about checking uniqueness in code.


Try something like this.
Code
Select All
// Return value of 0 means NOT UNIQUE.
// Return value of 1 means UNIQUE.

Function CheckUnique(vLEName as String, vLVal as String) as Int
var vRetVal as Int

	vRetVal = 1

	vLVal = @XLookup(@FN, vLVal, @Layout + "!" + vLEName, vLEName)
	If @Len(vLVal) > 0
	{
		vRetVal = 0
	}

	Return(vRetVal)

End Function
 


  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #4 - Aug 8th, 2007 at 8:28pm
Print Post Print Post  
Whoa.  Now that I'm going to have to study.

I'll give it a shot tomorrow.  Thanks for your help today, much appreciated as always.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read Only AND Unique?
Reply #5 - Aug 8th, 2007 at 8:36pm
Print Post Print Post  
I forgot a usage example!
Code
Select All
var vUnique as Int

    vUnique = CheckUnique("FullName", FullName)
    If vUnique = 0
    {
		@MsgBox("OMG! It's not unique! Ahhhhhh!!!!!", "", "")
    }
 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Read Only AND Unique?
Reply #6 - Aug 8th, 2007 at 8:51pm
Print Post Print Post  
2.0 also has @IsUnique()

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read Only AND Unique?
Reply #7 - Aug 8th, 2007 at 8:54pm
Print Post Print Post  
Quote:
2.0 also has @IsUnique()


Oh yeah! Use that instead.  Smiley
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #8 - Aug 9th, 2007 at 12:17pm
Print Post Print Post  
OK, I'm working with @IsUnique.  Here's the code I'm trying.  It's not working and I can't see why not:
Code
Select All
var vFirstLetter as string
var vFullName as string

// Capitalizes the first letter of the First Name

vFirstLetter = @Left(FirstName, 1)
vFirstLetter = ToUpper(vFirstLetter)
FirstName = @REPLFIR(FirstName, vFirstLetter, vFirstLetter)


// Creates vFullName from both name parts
IF NOT FullName = (FirstName + " " + LastName) then
	{
	vFullName = (FirstName + " " + LastName)
	}
// Checks to see if it's unique
If @IsUnique(FullName, vFullName) = 0
THEN
	{
	@MsgBox("This name is not unique.", "It already exists in the database.", "Please change the name or discard this record.")
	Clear(FullName)
	ThrowFocus(LastName)
	}
ELSE
// Sets the Full Name
	{
	FullName = vFullName
	} 



This sets FullName even if it already exists.  What have I done wrong?
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #9 - Aug 9th, 2007 at 12:24pm
Print Post Print Post  
When I swap the return value from 0 to 1 I get the error message I expect, I.E. changing the test to
Code
Select All
If @IsUnique(FullName, vFullName) = 1 


Is there a mixup in the book?

Also, acknowledging this msgbox takes 3 clicks.
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #10 - Aug 9th, 2007 at 12:28pm
Print Post Print Post  
Taking out the throwfocus and the Clear (which is not needed anyway) get the acknowledgment down to one click.

But I do think the values in the book are switched.  A return value of 1 is indicating a non-unique value, though the book says it should be 0.  Unless I've done something that is causing the switch.  In any event, this code works:
Code
Select All
var vFirstLetter as string
var vFullName as string

// Capitalizes the first letter of the First Name

vFirstLetter = @Left(FirstName, 1)
vFirstLetter = ToUpper(vFirstLetter)
FirstName = @REPLFIR(FirstName, vFirstLetter, vFirstLetter)


// Creates vFullName from both name parts
IF NOT FullName = (FirstName + " " + LastName) then
	{
	vFullName = (FirstName + " " + LastName)
	}
// Checks to see if it's unique
If @IsUnique(FullName, vFullName) = 1
THEN
	{
	@MsgBox("This name is not unique.", "It already exists in the database.", "Please change the name or discard this record.")
	}
ELSE
// Sets the Full Name
	{
	FullName = vFullName
	} 

  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #11 - Aug 9th, 2007 at 1:17pm
Print Post Print Post  
I take back what I just said.  The above code is firing on all entries, unique or not.  The book is most likely correct, and my code is most likely wrong.  Back to the drawing board.
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #12 - Aug 9th, 2007 at 2:02pm
Print Post Print Post  
I cannot get @IsUnique to fail.  That is, I am unable to meet the condition 0.  I've tried using both the variable and using a "specific string".  I've put the test into an element (LastName) that I know contains the string "Miara" (several extant records contain this) and even specifying "Miara" as the string to test in that element, as so
Code
Select All
If @IsUnique(LastName, "Miara") = 0 


does not find it to be non-unique.

On the flipside, testing for =1 works every time, unique or not.

I'm baffled.  Time for a fresh cup of coffee, maybe take a look at some of the Maxim pictures of Sarah Silverman, or maybe I'll balance the checkbook.  Nah, Silverman it is.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read Only AND Unique?
Reply #13 - Aug 9th, 2007 at 2:06pm
Print Post Print Post  
It's working fine for me using Customers. Does it work for you in Customers.db?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Read Only AND Unique?
Reply #14 - Aug 9th, 2007 at 2:31pm
Print Post Print Post  
Yes, when I did a straightforward comparison to an existing value.

I then copied some code into customers.db and did some tests.  It appears that the combination
(Firstname + " " + Lastname) is introducing a problem.  Perhaps it's the quotes?  This is what I did:
Code
Select All
on-change of First element

var vFullName as string


// Creates vFullName from both name parts
IF NOT City = (First + "r" + Last) then
	{
	vFullName = (First + "r" + Last)
	}
// Checks to see if it's unique
If @IsUnique(City, vFullName) = 0
THEN
	{
	@MsgBox("This name is not unique.", "It already exists in the database.", "Please change the name or discard this record.")
	}
ELSE
// Sets the Full Name
	{
	City = vFullName
	} 



I then entered PA into First and IS into Last (PARIS is an existing value in the city field of a record).  No error message, and City filled with "PAr".  Deleting PA from First, no error message, and City filled with "rIS"

It's stumbling over the concatenation.
  

**
Captain Infinity
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print