4D View Pro: Find and replace with code

Automatically translated from English

Sometimes when you initialize a 4D View Pro document, you need to find some values or tags in it and replace them with data issued from 4D. Now it’s a breeze with the VP Find command. Thanks to this command, you can find data, a formula, or a tag and replace it in the entire sheet or only a specific part of it!

Let’s find out how.

HDI VP Find

The VP Find command lets you search for a text value within a designated range in a 4D View Pro document’s text, formulas, or tags.

For example, if you want to perform a case-sensitive search for the first occurrence of the word “Total” in the text of the cells:

$range:=VP All("ViewProArea")
// find the first cell that contains the word 'Total' in the current sheet
$result:=VP Find($range; "Total")
// Make the cell background yellow for the found cells
VP SET CELL STYLE($result; New object("backColor"; "yellow"))

Now you can refine your search to find all of the cells containing “Total” by using the all property:

$range:=VP All("ViewProArea")
$condition:=New object
// Search in all values in the range
$condition.all:=True
// Find all cells containing the word 'Total' in the current sheet
$result:=VP Find($range; "Total"; $condition)
// Make the cell background yellow for the found cells
VP SET CELL STYLE($result; New object("backColor"; "yellow"))

  • If you want to perform a search for “Total” without taking the case into account, just modify the flags property:

$range:=VP All("ViewProArea")
$condition:=New object
// Search the entire sheet
$condition.all:=True
// Search cells containing the word "Total" without considering the case 
$condition.flags:=vk find flag ignore case
// Find all cells containing only the word 'Total' in the current sheet
$result:=VP Find($range; "Total"; $condition)
// Make the cell background yellow for the found cells
VP SET CELL STYLE($result; New object("backColor"; "yellow"))

  • If you want to replace all of the found “Total” words with “4D”, add a parameter with the replacement text:

$range:=VP All("ViewProArea")
$condition:=New object
// Search the entire sheet
$condition.all:=True
// Search cells containing the word "Total" without considering the case
$condition.flags:=vk find flag ignore case
// Replace text in all cells containing only 'Total' with "4D"
$result:=VP Find($range; "Total"; $condition;"4D")
// Make the cell background yellow for the found cells
VP SET CELL STYLE($result; New object("backColor"; "yellow"))

Of course, these are just a few of the possibilities enabled by the VP Find command.

Find out more in the doc center to learn more, like how to find values with wild cards, search in formulas, and much more.

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.