Normal Topic XLookupR: quotes for Key? (Read 798 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
XLookupR: quotes for Key?
Feb 8th, 2006 at 1:33pm
Print Post Print Post  
Sorry Bob, I should have started a new topic for my question rather than jumping into yours.

In another thread, I said:
Quote:
I have a button that assigns a code to a record much the way your "Record=" code does.  However, mine reads
Code
Select All
vNextNum = @ToNumber(@XLookupR(@FN, "99999999", "Code", "Code")) + 1 


I notice that my 99999999 is in quotes but yours is not.  Is there a difference in performance?  Is one preferred over the other?  What would be the conditions that would require one method over the other?

To which Bob replied:
Quote:
Sample was provided for sample of syntax highlighting, not for code sample.  Section was taken randomly to show many different highlight features.

Are quotes better in position two, the "key" code?   I am not sure.  The Sesame Programming Guidel shows no quotes on page 39.  The sample shown was looking for a number in a number field.  Is yours looking for a number in a text field?

Mine is a number field.  I have no idea why my "99999999" is in quotes, but the button seems to work (looks up the last saved customer code and increases the code by one).  I'm not fully comfortable with the XLookup commands and must have had help with this one, so perhaps I wrote it wrong in the process.  I'll take the quotes out if they shouldn't be there, or if it will work better without them.   I hope someone reading this can give some advice, and in the meantime I'll experiment.

One thing I wonder about...if I have multiple users accessing this database and adding customer records, is duplication of codes possible if one of them pushes the "Assign Code" button but delays saving the record until after another user has done the same thing?  If so I'll need to figure out a way to check for a unique value when saving.  Currently my programming doesn't do this.

Back to the Forum archives!  I'm sure this has been discussed before.
  

**
Captain Infinity
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: XLookupR: quotes for Key?
Reply #1 - Feb 8th, 2006 at 2:32pm
Print Post Print Post  
That parameter is always type string, without regard to the field/LE type that is being searched. SBasic will convert the parameter from number to string if you leave the quotes off. There will be a tiny performance penalty for the conversion - very tiny.

In general, you should always use the correct type for any parameter, even if SBasic does correct the type for you. It will make you program easier to read for both the humans and the computer.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
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: XLookupR: quotes for Key?
Reply #2 - Feb 8th, 2006 at 4:39pm
Print Post Print Post  
Thank you...but I'm still a bit confuzzled.  I hear you saying that it doesn't really matter in this instance because Sesame will interpret the string correctly in either case but performance will be a tiny bit better by using the quotes so it doesn't have to convert.  Gotcha.  So mine is a tiny bit better than Bob's, but both do the same thing.  Is that right?

What's confusing is that I'm not looking an exact match to "99999999" (as a text string) but a number in the range of all numbers less than 99999999.

But Sesame returns the retreived number as a text string...so that's why I have to use ToNumber, yes?  The parts are starting to come together but my brain is fighting me today.  I should have drank more beer in college, smoothed out some of those cerebral wrinkles, then I wouldn't have this problem.

The book is a bit confusing about this, too, because some of the examples show the Key in quotes and some are without.  I think my main objective (in this thread) is to lock down the idea and definition of the Key.
  

**
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: XLookupR: quotes for Key?
Reply #3 - Feb 8th, 2006 at 6:11pm
Print Post Print Post  
Quote:
Thank you...but I'm still a bit confuzzled.  I hear you saying that it doesn't really matter in this instance because Sesame will interpret the string correctly in either case but performance will be a tiny bit better by using the quotes so it doesn't have to convert.  Gotcha.  So mine is a tiny bit better than Bob's, but both do the same thing.  Is that right?


Yes both do the same thing

Quote:
What's confusing is that I'm not looking an exact match to "99999999" (as a text string) but a number in the range of all numbers less than 99999999.


You are looking for the highest number in the database that does not exceed 99999999. The R in XLookupR stands for Range as it does not return an exact match but the closest lower number that it can.

Quote:
But Sesame returns the retrieved number as a text string...so that's why I have to use ToNumber, yes?


Yes. All of the X commands that return a value return that value as a string.

Quote:
The book is a bit confusing about this, too, because some of the examples show the Key in quotes and some are without.  I think my main objective (in this thread) is to lock down the idea and definition of the Key.


The reason some of the examples have the key not in quotes is because the key value is an element on the form or a variable. If you use Key, without quotes, Sesame is going to look for a element or variable named Key and use the value in there. If you use "Key" with quotes then Sesame knows that the value you want to use to match is the Word "Key".

-Ray
  

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



Posts: 2530
Joined: Nov 22nd, 2002
Re: XLookupR: quotes for Key?
Reply #4 - Feb 8th, 2006 at 6:14pm
Print Post Print Post  
A you said, it doesn't really (as in functionally) make much difference. If the key LE is a numeric, and you specify a numeric argument (even though the parameter type is string):

1. SBasic converts the number 999999 into a string.
2. Passes the string "999999" to the actual function.
3. The "real" XLookup function checks the field type of the field bound to the key LE - if it is numeric, it converts the string "999999" into the number 999999.0.
4. That number is compared to the numeric field value in the target field (in the matching record type records) using a numeric comparison.
5. If they have the same numeric value, the return value is (if need be) converted to a string and returned.

If you pass in a key value in quotes, Sesame can skip step one. 99.99% of the time is spent on step 4.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
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: XLookupR: quotes for Key?
Reply #5 - Feb 8th, 2006 at 7:10pm
Print Post Print Post  
Thank you both, that's very helpful.   Smiley
  

**
Captain Infinity
Back to top
IP Logged