Code a range in 4D View Pro

Automatically translated from English

4D v17 R4 brings new features to 4D View Pro and one of them is the creation of ranges with code.

First, you need to define a range object to manipulate your cells by programming. You can do this in 4D View Pro with the following new commands: VP Cell, VP Cells, VP Column, VP Row, VP All and VP Combine ranges.

A range object can define:

  • a cell or a group of cells,
  • a column or a group of columns,
  • a row or a group of rows
  • all the cells of a sheet.

define a cell or a group of cells

To define coordinates of a single cell, use the VP Cell command:

$column:=3 //column of beginning cell
$row:=5 //row of beginning cell
$sheet:=2 // specific workbook sheet
$cellObj1:=VP Cell ("ViewProArea";$column;$row) // cell D6 (current sheet)
$cellObj2:=VP Cell ("ViewProArea";$column;$row;$sheet) // cell D6 sheet 3

   Keep in mind that the row index, the column index, and the sheet index start at 0. So the coordinates of the first upper left cell is (0;0)!

A group of cells is basically defined by referencing the upper left cell and the count of rows and cells. Pass this information to the VP Cells command:

$column:=3 //column of beginning cell
$row:=5 //row of beginning cell
$columnCount:=2 // total number of columns
$rowCount:=3 // total number of rows
$sheet:=2 // specific workbook sheet
$cellsObj1:=VP Cells ("ViewProArea";$column;$row;$columnCount;$rowCount) // cells D6 to E8 (current sheet)
$cellsObj2:=VP Cells ("ViewProArea";$column;$row;$columnCount;$rowCount;$sheet) // cells D6 to E8 on sheet 3

define a column or a group of columns

To define a column’s coordinate, pass the column index to the VP Column command. If you need to define several contiguous columns, add a column count after the column index:

$column:=3 // beginning column
$columnCount:=2 // total number of columns
$sheet:=2 // specific workbook sheet
$colObj1:=VP Column ("ViewProArea";$column) // column D (current sheet)
$colObj2:=VP Column ("ViewProArea";$column;$columnCount) // column D + column E (current sheet)
$colObj3:=VP Column ("ViewProArea";$column;$columnCount;$sheet) // column D + column E sheet 3

define a row or a group of rows

To define a row’s coordinates, pass the column index to the command VP Row. If you need to define several contiguous rows, add a row count after the row index:

$row:=5 // beginning row
$rowCount:=3 // total number of rows
$sheet:=2 // specific workbook sheet
$rowObj1:=VP Row ("ViewProArea";$row) // row 6
$rowObj2:=VP Row ("ViewProArea";$row;$rowCount) // row 6 + row 7 + row 8
$rowObj3:=VP Row ("ViewProArea";$row;$rowCount;$sheet) // row 6 + row 7 + row 8 sheet 2

define an irregular cell range

An irregular cell range is when you need to combine several, separate (discontinuous) groups of cells within the same range. To do so, create an individual range for each continuous group, then pass them all in parameter to the VP Combine ranges command:

$combine:=VP Combine ranges ($cellObj1;$colObj1;$rowObj1;rowObj2;cellsObj2)

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.