Hot Topic (More than 10 Replies) Read Only AND Unique? (Read 6167 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
 
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 #15 - Aug 9th, 2007 at 3:25pm
Print Post Print Post  
OK, I removed all concatenation programming, and programmed in a test that HAS to be flagged, as so:
Code
Select All
on-change of Firstname element

var vFull as string

vFull = Firstname

// Checks to see if it's unique
If @IsUnique(Firstname, vFull) = 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
	{
	FullName = vFull
	} 



I entered "Scott" in the Firstname field, and tabbed out.  I already exist in the database.  No error message, and Fullname happily filled with "Scott".

Then I did this:
Code
Select All
var vFull as string

// Capitalizes each word
cuInitialCaps()


vFull = "Scott"
// Checks to see if it's unique
If @IsUnique(Firstname, vFull) = 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
	{
	FullName = vFull
	} 



Still no error, Fullname fills with Scott.

Then I did this, turned off the variable entirely:
Code
Select All
var vFull as string

// vFull = "Scott"
// Checks to see if it's unique
If @IsUnique(Firstname, "Scott") = 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
	{
	FullName = vFull
	} 



Still no error message.
  

**
Captain Infinity
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 #16 - Aug 9th, 2007 at 3:53pm
Print Post Print Post  
Hello Scott,

Do you have more than one form in the application you are working in?

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
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 #17 - Aug 9th, 2007 at 3:57pm
Print Post Print Post  
No sir, I do not.
  

**
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 #18 - Aug 9th, 2007 at 4:07pm
Print Post Print Post  
I'm officially giving up on this.  Thanks to everyone who pitched in to help, Erika, Ray.  I'm going to set it unique but writeable in properties and move on to some other project.  Thanks again.
  

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


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Read Only AND Unique?
Reply #19 - Aug 9th, 2007 at 4:45pm
Print Post Print Post  
Keep it Unigue and writeable when @NEW, and make it ReadOnly once it has been committed and saved?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
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 #20 - Aug 9th, 2007 at 5:07pm
Print Post Print Post  
Yeah, OK, thanks Bob, that sounds good, I'll try that.

I did try one other thing after lunch: I made a completely new application with one database and one form.  Three elements: Firstname, Lastname, Fullname.  Programmed Lastname to concatenate on-change and test for uniqueness.  Went into preview, added 1 record.  Advanced, added the same data...and the test for uniqueness worked and I got the error message. 

When I use the exact same programming in my Personnel database, which also has just 1 form and the three same elements, it fails.  So clearly I've got some gremlins in Personnel.  I've Writelined the values of all the elements and the variable and they're exactly what I expect them to be.  Is there a way to Writeln the integer that is returned from @IsUnique?

But anyway, I've wasted most of the day on this and I'm very frustrated, and since it's really not vital in the long run because uniqueness can be set in properties, I think I'll move on.  Thanks again to everyone who tried to help, your support is much appreciated.

  

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


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Read Only AND Unique?
Reply #21 - Aug 9th, 2007 at 5:15pm
Print Post Print Post  
Ypu asked: Any way to writeln the integer returned by the @Unique?

WriteLn the @Unique formula.  Example:
WriteLn ( "The value of @Unique is: " + @IsUnique(Firstname, vFull) )
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
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 #22 - Aug 9th, 2007 at 6:02pm
Print Post Print Post  
Thanks Bob, I'll try that, see what it shows me.

Here's something else I'd like to try.  When FullName changes, I'd like to do a lookup into the database using its value as a key, into the same field.  Is that possible, or would it be whatchacall "recursive"?  If I create a variable I could use @Xlookup.  I'm thinking of something like this:
Code
Select All
on-change event of FullName

var vFullTest as string

NotifyForm(0) // Initialize save state

If @IsNew then
vFullTest = @XLookup(@FN, FullName, "Employee!FullName", "FullName")
	IF @error then
		{
		Writeln("Lookup Failed")
		}
	ELSE  // I'll cross this bridge when I come to it; so far every lookup has failed 

  

**
Captain Infinity
Back to top
IP Logged