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