See attached. We have a table with fields 'a' and 'b', we are reading it and trying to update a subset of records. This script first collects all changes and then applies them: ' VBScript Sub Main Set app = Manifold.Application Set db = app.GetDatabaseRoot() Set table = db.Search("t") ' change records with [a] < 200: set [b] to [a]+1 ' create temporary table to hold changes Set changes = app.CreateTable() ' creates mfd_id / mfd_id_x Set schema = changes.GetSchema() schema.AddField "b", "int32" changes.Design schema ' prepare to collect changes Set valuesNew = app.CreateValueSet() valuesNew.AddValue "mfd_id" valuesNew.AddValue "b" ' collect changes Set records = table.SearchAll(Array("mfd_id", "a")) If records Is Nothing Then app.Log "No records" app.OpenLog Exit Sub End If Do While records.Fetch Set valuesOld = records.GetValues() a = CInt(valuesOld(1).Data) If a < 200 Then valuesNew(0).Data = valuesOld(0).Data valuesNew(1).Data = a+1 changes.Insert valuesNew End If Loop ' apply changes Set records = changes.SearchAll(Array("mfd_id", "b")) If records Is Nothing Then app.Log "No changes" app.OpenLog Exit Sub End If Set records = records.Recompose(Array("mfd_id"), Array("b")) ' tell the table "mfd_id" ' ask the table to change "b" updated = table.UpdateBatch("mfd_id_x", records) app.Log "Records updated: " & updated app.OpenLog End Sub Hope this helps. Attachments: read-write-table-from-script.mxb
|