Normal Topic Programming @Number (Read 9042 times)
wildwood
Full Member
***
Offline


No personal text

Posts: 156
Location: New York
Joined: Apr 2nd, 2004
Programming @Number
Jan 23rd, 2005 at 3:10pm
Print Post Print Post  
I have a customer application which places a number (numeric) in consecutive order in the Customer ID# element. Thus each new customer receives an ID# in increments of 1. I am having difficulty in determining where to place the following (if correct) programming:

if @add and CustomerID# = "" then CustomerID# = @Number

Does it get placed in:
On Element Entry, On Element Exit, On Form Change, On Element Change, On Form Entry, On Form Exit, On Element Immediate Change, or a combination of the above?

I dont want it to fire upon form entry because if I decide to cancel the form (exit without saving) it still will fire. Or if you go backwards (F9) it fires again.

If there is better programming for consecutive order of a number in adding a record let me know.

Peter
  
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: Programming @Number
Reply #1 - Jan 23rd, 2005 at 4:51pm
Print Post Print Post  
There are a number of techniques to use.  You can use @Number, you can use GlobalValues, you can use CustomerID#=@ToNumber(@XLookupR(@Filename,99999,"CustomerID#","CustomerID#"))+1

But independent of which technique you use, more information may be needed for a really correct answer. 

Where to put the programming depends what and when you want to do something with the CustomerID# value.  It may depend on if you are a stand alone system or working in a network with multiple records being added at the same time.  If you are doing nothing until the record is saved then you can use the programming on Form Exit.  If you need to use the CustomerID# in other programming before you save the record then you may want to use on Element Exit/Enter or FormEnter.  This would have to be done if assigning the CustomerID# to line items in an order before the Parent Order is saved.

If you assign the value before Form Exit and you are on a network you may need to do some FormExit checking to make sure the new CustomerID# has not already been assigned by another user before saving the record.  If it was assigned, you may have to call some sub routine to reassign the number and do the processing again that was done on Element Exit, then recheck again before saving.

Since Q&A 4.0 provided the @XLR function, I have stopped using the older @number technique and most frequently use the @XLR formula.  Sesame now requires that the XLR result must be converted to a number (@TN), so minor changes are needed to files translated from Q&A
  



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: Programming @Number
Reply #2 - Jan 23rd, 2005 at 5:15pm
Print Post Print Post  
Bob Hansen makes excellent points, Here is my simplistic explanation. It might be helpful as a starting point.


Wildwood,

There are many ways to accomplish a unique record number in Sesame. 1 way that seems simple and efficient is using a global value. I can not guarantee this is the best way but it seems to work for me.

I place this line of code in any element for on form entry.


Globalvalue ("RecNum", RecNum) // this is placing record number in the global value holder



Then this next piece of code can be added to a number of places.

You can place this in on element exit of the last field you will use.

Or you can execute the code based on a question you ask the user (do you want to keep this record)
Or possibly on form exit of a field.


Var vRecNum as Int   // Declare your variable


If @IsBlank(RecNum) Then
     {
           //Set record Number for a custumer id
           vRecNum = @TN(@GlobalValue("vNextRECNum"))
           RecNum = vRecNum
           GlobalValue("vNextRecNum", @Str(vRecNum + 1))

     }


To use this exact example just to see how it works in a simple example

Open any dsr
Add an element named RecNum
Save layout design
Go to program layout
Place this line in any on form entry element
Globalvalue ("RecNum", RecNum) // this is placing record number in the global value holder

Place this in any on element exit

Var vRecNum as Int   // Declare your variable


If @IsBlank(RecNum) Then
     {
           //Set record Number for a custumer id
           vRecNum = @TN(@GlobalValue("vNextRECNum"))
           RecNum = vRecNum
           GlobalValue("vNextRecNum", @Str(vRecNum + 1))

     }

save layout design

now when you exit the element you placed the code in it will enter the next number in the RecNum field.

This is just the basics you can add much more to check other conditions, I was just trying to keep this simple.

I am pretty sure the Lanticans and others will pipe in with other and possibly better suggestions.

Good luck.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
wildwood
Full Member
***
Offline


No personal text

Posts: 156
Location: New York
Joined: Apr 2nd, 2004
Re: Programming @Number
Reply #3 - Jan 23rd, 2005 at 6:23pm
Print Post Print Post  
Hey Bobscott and Bob_Hanson thanks for the help!
Bobscott I implemented your programming solution and it seem to work fine. However, if I wanted to start the RecNum field from lets say 101 how do I implement that into your program. I can not change it from your original starting point of 0.

Peter
  
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: Programming @Number
Reply #4 - Jan 23rd, 2005 at 7:51pm
Print Post Print Post  
You can start application with something like this:

Code
Select All
IF @Globalvalue("vNextRecNum") = "" THEN {
	Globalvalue ("vNextRecNum", 101)
	} 

  



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


No personal text

Posts: 156
Location: New York
Joined: Apr 2nd, 2004
Re: Programming @Number
Reply #5 - Jan 23rd, 2005 at 9:48pm
Print Post Print Post  
Bob where do I put this code:

IF @Globalvalue("vNextRecNum") = "" THEN {
Globalvalue ("vNextRecNum", 101)
}

based on the programming Bobscott setup?

I've placed it in a few different LE's and it still returns an increase of 1 from the starting point of 1.

Peter
  
Back to top
 
IP Logged
 
beagle
Junior Member
**
Offline


No personal text

Posts: 80
Location: australia
Joined: May 28th, 2004
Re: Programming @Number
Reply #6 - Jan 24th, 2005 at 2:49am
Print Post Print Post  
Hi Wildwood,

To change your starting number start your application in sdesigner.

click the Application property manager.
3rd field down in the application properties is @number field.
set this to 100
save your changes.

(a tool tip field should appear if you pause your mouse pointer over the field explaining things - nice touch lantica!)

when you enter a field using @nmb your first number will be 101

this change will be carried accross to the "live" sesame when you reconcile your application
  
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: Programming @Number
Reply #7 - Jan 24th, 2005 at 3:44am
Print Post Print Post  
Good suggestion Beagle but that will only work if he is using @NUMBER.

If using the Global Value, he can put the programming in the Version 1.1 new tool for running programming when the application starts.

Open the DSR file in Designer.
Expand Application, select Application Property Manager.
Click on Program Application.
Insert the programming.
Code
Select All
var vNextRecNum as Int

IF @Globalvalue("vNextRecNum") = "" THEN {
     Globalvalue ("vNextRecNum", 101)
     } 

Test it for no errors.
Save Changes.
Reconcile with the application.

--------------------------------------------
Modified earlier program to define the variable vNextRecNum to be available for the IF statement.  The details above are untested, be prepared to debug. Roll Eyes
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Programming @Number
Reply #8 - Jan 24th, 2005 at 1:47pm
Print Post Print Post  
For what it's worth, the code that initializes the GlobalValue does not need to be permanently in the application. You can run a Mass Update on a single record to set the GlobalValue to 101.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged