Normal Topic Incrementing a record# using @XLR (Read 1170 times)
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Incrementing a record# using @XLR
Feb 19th, 2004 at 10:53pm
Print Post Print Post  
Lanticans,

I was asked by another forum member who was at wits end attempting to use the code you describe on your FAQ page if I could help figure out what he had wrong with his implementation of this code.

******
(How do I create a unique sequential number for each record (@Number)?
you can also use the handy technique of adding one to the highest existing number in that field with programming like this ...

IF ID = "" THEN ID = @XLR(@fn,99999,"ID","ID")+1

This is the method I'd use. It is easy to copy to other fields, you can use it in as many fields as you want, and requires no "@Number maintenance")

********

He could not get this to increase the number by 1 properly and when he e-mailed me the dsr I realized it was literally adding a 1 not doing the math. I changed the field from text to number thinking that was the problem.

NOPE that did not help.

I ended up using this code basically the same as described in the Inside Sesame check program article to accomplish the task.

If  ID = "" Then
ID= @Tonumber(@XLookupR(@Fn, 999999, "ID", "ID")) + 1

Is the FAQ incorrect or have I missed something? I am fearful I am giving out incorrect information on this matter  Lips Sealed

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Incrementing a record# using @XLR
Reply #1 - Feb 19th, 2004 at 11:42pm
Print Post Print Post  
Bob, I use this code all the time and it works for me. As a matter of fact I have been using this for last several years for counters.

1. In Sesame you have to use @tonumber even though field is Number type because xlookup value is always string (text)  type.

2. If the ID# has exeeded 6 digits then you will have to use more "9"s.

3. If you have more than one form in the application, you will have to use the Form name in front of first ID.

4. You have to save it into .db and test .db as preview would not work with x-family commands.

5. Use with following code on Form entry event
If  @IsNew and ID = "" Then
ID= @Tonumber(@XLookupR(@Fn, 999999, "ID", "ID")) + 1


Even after doing this, if it does not work for you, I will send you one of my applications with this working properly.

The formula you use seems to be all right.  
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Incrementing a record# using @XLR
Reply #2 - Feb 20th, 2004 at 12:00am
Print Post Print Post  
Bharat,

Thanks for the offer.

I have no problem with the @tonumber version. That is what I forwarded that worked. I was concerned that the version on the FAQ that the user was attempting to use might be better and I could not get that one to work.

Or if the FAQ is incorrect I would not want anyone else wasting time or getting frustrated trying to use it.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Incrementing a record# using @XLR
Reply #3 - Feb 20th, 2004 at 12:10am
Print Post Print Post  
I misunderstood you.  I thought, it did not work for you. I did not realize that you were pressing the issue about incorrect FAQ.

In Q&A, it would work as it is given in FAQ.  In Sesame, xlookup value is always in string so, we have to use Typecasting function, @tonumber to convert into number. 

I agree with you whole-heartedly that FAQ should be amended. Once again, I apologize for the misunderstanding.

  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Incrementing a record# using @XLR
Reply #4 - Feb 20th, 2004 at 12:43am
Print Post Print Post  
Bharat,

No apologies are ever necessary. I always look forward to your comments, suggestions and help. It is always comforting, knowing that you and the other forum members are out there with an offer of help.  Cheesy
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Alec
Lanticans
*****
Offline



Posts: 200
Location: Ascot, England, UK
Joined: Nov 22nd, 2002
Re: Incrementing a record# using @XLR
Reply #5 - Feb 20th, 2004 at 11:32am
Print Post Print Post  
OK. Yes. You're right! - The FAQ is wrong!  And it's my fault.  I didn't check it in Sesame.  'Spose it's Guantanamo bay for me Sad  Never mind, they say it's nice there this time of year.

The reason for the discrepancy is, as you say Robert, the strict typecasting of Sesame.  Lookups and XLookups ALWAYS return text, in Q&A as well as Sesame.  It's just that Q&A has the ability to be able to mix'n'match them and make an educated guess as to what you want, and gets it right some of the time. Sesame applies strict rules. It's more rigourous, and it's more logical.

The following will work, if the LE "Number1" is bound to a Number field..

IF Number1 = "" THEN Number1 = @TN(@XLR(@fn,99999,"Number1","Number1"))+1 

Notice that it's the XLookupR that has the @ToNumber wrapped around it. The "+1" is outside the parentheses.

The field being incremented MUST be a number field.  If you use a text field it will seem to work but will, eg in the example I used, get stuck at 10.  This is because Sesame is not sorting the text values as numbers and determining the highest value.  It sorts 9 higher than 10 because it starts with a 9: it's sorting left to right.

I'll get the FAQ changed forthwith.

A question: would you like programming examples to use the full names of functions, or abbreviations. These two are the same...

IF Number1 = "" THEN Number1 = @TN(@XLR(@fn,99999,"Number1","Number1"))+1 

IF Number1 = "" THEN Number1 = @ToNumber(@XLookupR(@fn,99999,"Number1","Number1"))+1 

My view is that the full version is recognisable to more users and is preferred.

BTW - don't forget that you can't check this is preview mode. XLookups, and all the X family (XUserSelect etc), do not work in preview mode.  This includes Lookup & @Lookup (internal lookup table), as it's actually an XLookup to another Sesame database so is an XLookup under the bonnet.
  

Alec
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: Incrementing a record# using @XLR
Reply #6 - Feb 20th, 2004 at 1:07pm
Print Post Print Post  
The FULL name version would be my choice:

IF Number1 = "" THEN Number1 = @ToNumber(@XLookupR(@FileName,99999,"Number1","Number1"))+1   
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Incrementing a record# using @XLR
Reply #7 - Feb 20th, 2004 at 2:08pm
Print Post Print Post  
I like the FULL name to please.  Smiley
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Alec
Lanticans
*****
Offline



Posts: 200
Location: Ascot, England, UK
Joined: Nov 22nd, 2002
Re: Incrementing a record# using @XLR
Reply #8 - Feb 20th, 2004 at 2:10pm
Print Post Print Post  
Yes, that's right Bob - I failed to notice that "@FN" is an abbreviation too.  Habit!
  

Alec
Back to top
IP Logged