Use collections to write and read in 4D View Pro

Automatically translated from English

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))

Fabrice Mainguené

• Product Owner •

Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.

After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.