4D Blog

Home Product 4D View Pro: Use 4D formulas in your spreadsheet

4D View Pro: Use 4D formulas in your spreadsheet

October 27, 2020

Product

4D v18 R5 introduces a new command that simplifies writing your code: VP SET CUSTOM FUNCTIONS. It creates custom functions in 4D View Pro which execute 4D formulas.

Thanks to this command you can now allow 4D commands, fields, variables, methods, or any arbitrary expression to be used in your cell formulas. For example, there’s no need to create a method to use a simple variable in 4D View Pro, just pass it as a parameter to your Formula.

HDI: Allow formulas

VP SET CUSTOM FUNCTIONS allows 4D View Pro access to:

  • 4D variables
  • fields
  • methods
  • 4D commands

 

During the on load event, you need to declare all of the 4D expressions you want to access in 4D View Pro.

First, create an object and use the object’s attribute to define your method’s call name:

$o:=New object

//Name of the function in 4D View Pro: "DRIVERS_LICENCE"
$o.DRIVERS_LICENCE:=New object

Then, add a formula attribute that contains the formula based upon your expression. This expression will be calculated when used in your cells.

If your DRIVERS_LICENCE function refers to:

  • a global variable:

$o.DRIVERS_LICENCE.formula:=Formula(DriverLicence)

  • a field table:

$o.DRIVERS_LICENCE.formula:=Formula([Users]DriverLicence)

  • a method:

$o.DRIVERS_LICENCE.formula:=Formula(DriverLicenceState)

  • a 4D command:

$o.DRIVERS_LICENCE:=Formula(Choose(DriverLicence; "Obtained"; "Failed"))

  • a 4D expression:

$o.DRIVERS_LICENCE.formula:=Formula(ds.Users.get($1).DriverLicence)
$o.DRIVERS_LICENCE.parameters:=New collection
$o.DRIVERS_LICENCE.parameters.push(New object("name"; "ID"; "type"; Is longint))

You can add a description of what your function does:

$o.DRIVERS_LICENCE.summary:="Returns the result of the driver's license"

And if you refer to a method, you can add some parameters like the name and the type of the expected parameters by your function:


$o
.BIRTH_INFORMATION:=New object
$o.BIRTH_INFORMATION.formula:=Formula(BirthInformation)
$o.BIRTH_INFORMATION.parameters:=New collection
$o.BIRTH_INFORMATION.parameters.push(New object("name";"First name";"type";Is text))
$o.BIRTH_INFORMATION.parameters.push(New object("name";"Birthday";"type";Is date))
$o.BIRTH_INFORMATION.parameters.push(New object("name";"Time of birth";"type";Is time))
$o.BIRTH_INFORMATION.summary:="Returns a formatted string from given information"

When you finish filling your object with all of the information, you need to make it available in 4D View Pro. Simply pass it to the VP SET CUSTOM FUNCTIONS command:

VP SET CUSTOM FUNCTIONS("ViewProArea"; $o)

And voilà! The new function is available in 4D View Pro:

blank

 

Discuss

Tags 4D View Pro, v18 R5, v19

Latest related posts

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

  • April 28, 2025

    Unlock the Power of AI with 4D AIKit: Automate, Create, and Innovate

  • April 25, 2025

    Formulas in Label Wizard

Fabrice Mainguené
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.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy