View Single Post
  #14 (permalink)  
Old 03-04-04, 19:36
Yuri Korin Yuri Korin is offline
Registered User
 
Join Date: Feb 2004
Location: Gold Coast, Queensland, Australia
Posts: 15
Talking

[QUOTE][SIZE=1]Originally posted by dmacd
Hi it is still locking up my system....

The fields being modded are key fields....Surname is changing from 'John Smith' to 'Smith' , so do I need to do something to prevent my table re-ordering every time I write a record?

Thanks,

Dawn

Hi,
I should have checked to see if there was any index processing involved with this exercise. Just for the programming exercise, which we all need, I have rewritten the script to accomodate a primary index. This should overcome your locking up problem, I hope.

method run(var eventInfo Event)
var
tcPersons tCursor
CurrSurname String
foreEnd smallint ; this holds the position of the space between
; the Forename and the Surname
srnmLong smallint
RecCount longint

tbPersons Table
arFieldNames Array[1] String
dyAttrib DynArray[]AnyType
endvar

tbPersons.attach("YourTable.db")
tbPersons.setExclusive()

; delete YourTable.db primary index
if not tbPersons.dropIndex() then
msgInfo("Error", "Can't drop YourTable.db primary index.")
return
endIf

if tcPersons.open(tbPersons) = FALSE then
msgStop("Stop!", "Can't lock YourTable.db table.")
return
endif

tcPersons.edit()
tcPersons.home()
RecCount = 0
scan tcPersons:
CurrSurname = tcPersons.Surname
foreEnd = CurrSurname.search(" ") ; find position of the space between names
tcPersons.Forename = substr(CurrSurname,1,foreEnd-1)
srnmLong = CurrSurname.size() - foreEnd
tcPersons.Surname = substr(CurrSurname,foreEnd+1,srnmLong)
RecCount = RecCount + 1
tcPersons.postRecord()
endScan

; Now recreate the primary index
arFieldNames[1] = "Surname"
dyAttrib["PRIMARY"] = True
dyAttrib["MAINTAINED"] = True
if not tcPersons.createIndex(dyAttrib, arFieldNames) then
errorShow()
endif

tcPersons.endEdit()
tcPersons.close()
tbPersons.unAttach()
msgInfo("Records processed","The number of records processed was "+string(RecCount)+".")

endMethod

Good luck.
__________________
YuriK
Reply With Quote