If you need to read or write hundreds of different values or formulas, you can do it faster, easier, and at the same time by using collections. New commands are available for this: VP SET VALUES, VP Get values, VP SET FORMULAS, and VP Get formulas.
Read/write values
To set values in cells, create a collection where each element represents a row. Each row is a collection of cell values to be set in the columns. See the example below:
$values:=New collection
// First row
$values.push(New collection("ID"; "Monday";"Tuesday";"Wednesday";"Thursday"; "Friday";"Saturday";"Sunday"))
// Second row
$values.push(New collection(1;1778;5656;22269;2964;20890;32189;26212))
// Write all values in the document
VP SET VALUES (VP Cell ("ViewProArea";1;1);$values)
To retrieve the values, simply pass a range that includes the cells you want to VP Get values. The command returns the values in the corresponding collections.
$values:=VP Get values (VP Cells ("ViewProArea";1;1;8;2))
See the commands in action in this HDI:
HDI: Read and Write Cell Values
Read/write formulas
The same concept also applies to formulas. To set formulas in the cells of your 4D View Pro document, you need to create a range to designate the first cell. Then create the desired collections and pass them as parameters to VP SET FORMULAS:
$formulas:=New collection
// First row
$formulas.push(New collection("myMethod(I3)";"MAX(A1,B2,C3,D4,E5)"))
// Second row
$formulas.push(New collection("SUM(C5:I5)";"AVERAGE(C5:I5)"))
// Set the cells with the formulas
VP SET FORMULAS (VP Cell ("ViewProArea";5;15);$formulas)
To get formulas, just pass a range that includes the cells with the formulas to the VP Get formulas command:
$formulas:=VP Get formulas (VP Cells ("ViewProArea";5;15;2;3))