macGrrl Posted January 27, 2005 Share Posted January 27, 2005 Trying to increase VOL_ID (number,unique) in script for new record. Tried Set next serial value = VOL_ID+1 which showed next number in sequence. Then if deleting (user changes mind about new record), I want to set the VOL_ID back one number. Tried VOL_ID-1 but that placed the next value of VOL_ID as -1. PS: Did this forum just have a massive changeover in apperance (edit screen)? Link to comment Share on other sites More sharing options...
The Digital Man Posted January 27, 2005 Share Posted January 27, 2005 Best thing to do is DO NOT CREATE THE RECORD until the user has CONFIRMED they want it. If it were me I would set up a data entry screen using global variables. With an ADD RECORD button or whatever at the bottom. When they finished filling in the record if they changed their mind and hit CANCEL instead - no harm done. You dump the variables and your VOL_ID stays where it should. If they choose to ADD you then CREATE the NEW RECORD and dump their variables into it. Having said that will VOL_ID+(-1) work? Link to comment Share on other sites More sharing options...
Kendoka Posted February 10, 2005 Share Posted February 10, 2005 Why not use: Max(AllRecords::SerialNumber)+1 ...when creating a new record??? Much simpler (and you don't have to mess with decresing the VOL_ID when someone deletes a record). Link to comment Share on other sites More sharing options...
Ender Posted February 10, 2005 Share Posted February 10, 2005 The trouble with Max() is it can get slow for large record sets, as it has to check all values to look for the Max. Using Last() is faster. Link to comment Share on other sites More sharing options...
comment Posted February 11, 2005 Share Posted February 11, 2005 How about Set Next Serial Value [ table::VOL_ID ; Get ( TotalRecordCount ) + 1 ] Link to comment Share on other sites More sharing options...
Ender Posted February 11, 2005 Share Posted February 11, 2005 Using Get(TotalRecordCount) will cause duplicates if records are ever deleted. Link to comment Share on other sites More sharing options...
aaa Posted February 11, 2005 Share Posted February 11, 2005 Most conveniently works the script "new record": In this case you can change vol_id as want. This script is: New Record Request vol_Id=1 loop .... exitloopif(isempty(self_relation_on_vol_id::vol_id)) .... set field(vol_id,vol_id+1) endloop Now if you validate vol_Id as unique, you can even change it. Link to comment Share on other sites More sharing options...
comment Posted February 11, 2005 Share Posted February 11, 2005 [ QUOTE ] Using Get(TotalRecordCount) will cause duplicates if records are ever deleted. [/ QUOTE ] Perhaps I haven't been clear enough. My suggestion was meant to be used when deleting the new, unwanted record. If other records can be deleted, then what's the point in insisting on a consecutive sequence of serial numbers? Link to comment Share on other sites More sharing options...
Ender Posted February 12, 2005 Share Posted February 12, 2005 In addition to the possibility of old records being purged at some point, there is the problem of duplicates happening in a multi-user environment when using Get(TotalRecordCount): User 1 creates the 10th record, with ID = 10. User 2 creates the 11th record, with ID = 11. User 1 aborts, deleting record ID 10. There are now 10 records, the next ID is reset to 11. User 3 creates the 11th record, with ID = 11. Now there are two records with ID = 11. Of course, using Max() or Last() is still not the best solution, as these could have skipped IDs in a multi-user environment. Link to comment Share on other sites More sharing options...
comment Posted February 12, 2005 Share Posted February 12, 2005 None of these is the best solution. That's the trouble with answering the question "as is". In a multi-user environment, I'd go with the Digital Man's suggestion. I use a somewhat similar method myself, in a single-user environment: There is always one empty record in the file. When the user clicks New.., the file goes to the empty record. If the user decides to Add Record (Are you sure?), the record is marked as Registered, and a new empty record is generated. Because this is strictly single-user environment (runtime), I was able to avoid the extra global fields (and the hassle of getting them to validate). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.