This is the script produced by the Memorized Calculations
example. (Your browser might not show it with proper indentation, but the
original is indented appropriately.)
'
' Name: Countries.ReturnArea
'
' Date: February 27, 2000 at 10:12 PM
'
' Description: Performs a series of selections, definitions, and calculations on one table.
'
' Comments: Produced by the Quantitative Decisions "Memorized Calculations" extension.
'------------------------------------------------------------------------------------------'
strTitle = "Countries.ReturnArea"
strTable = "Attributes of Countries"
theTable = av.GetProject.FindDoc(strTable)
if (theTable = NIL) then
MsgBox.Error("Table " + strTable.Quote + " not found.", strTitle)
return NIL
end
theVTab = theTable.GetVTab
beganTransaction = false
isGood = false
while (isGood.Not)
'
' (This is the comment entered with the Comment button.)
'
bmpSelection = theVTab.GetSelection
strQuery = "(true)"
theVTab.Query(strQuery, bmpSelection, #VTAB_SELTYPE_NEW)
theVTab.UpdateSelection
if (theVTab.CanEdit.Not) then
MsgBox.Info("Edits to this table cannot be saved.", strTitle)
end
isEditing = theVTab.IsBeingEditedWithRecovery
if (isEditing.Not) then
applyNow = theVTab.StartEditingWithRecovery
else
applyNow = TRUE
end
if (not applyNow) then
msgBox.Info("The table is not editable so the calculation will not be performed.", strTitle)
break
else
theVTab.BeginTransaction
beganTransaction = true
end
strField = "Area"
theField = theVTab.FindField(strField)
if (theField = NIL) then
theField = Field.Make(strField, #FIELD_DECIMAL, 12, 3)
if (theField <> NIL) then
theVTab.AddFields({theField})
theField.SetAlias(strField)
else
break
end
end
strCalc = "[Shape].ReturnArea / 1000000"
if (theVTab.Calculate(strCalc, theField).not) then
break
end
isGood = true
end
if (beganTransaction) then
theVTab.EndTransaction
end
if (isGood and isEditing.Not) then
theVTab.StopEditingWithRecovery(true)
elseif (isGood.Not and isEditing) then
theVtab.Undo
elseif (isGood.Not and isEditing.Not) then
theVTab.StopEditingWithRecovery(false)
else
' (Calculations worked, but started in an editing state, so leave it there.)
end
theTable.GetWin.Invalidate
' end of script.
