KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Creating your own constants in 4D
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: July 9, 1999
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

4th Dimension version 6.0.x allows you to use Constants in your code. A constant simply represents a value that will never change. Some examples of constants in 4D are:


  • On Load
  • Red
  • Is new Record
  • Pi
  • Return
  • Tab


The above constants simply replace numbers or text and are usually easier to remember than the numbers they represent. Notice that they are underlined.

Examples of using constants in 4D Code:

  If(Is new record([Table1])

  If(Form Event=On Load)

  Set Background Color(vObject;-Red)

In version 6.5 of 4D, developers can create their own constants using an application such as Resedit.


  1. Make a backup copy of your structure.
  2. Open a COPY of your structure with Resedit.
  3. Create a new resource of type 4DK#.
  4. Close the window titled "4DK# ID = 128 from (your database name here)".
  5. Choose Get Resource Info from the Resource menu and change the ID to 15000.
  6. Type in a name such as "My Constants
  7. Close the Resource Info window and then select the line which reads 15000.
  8. Choose "Open Using Template..." from the Resource menu. Type STR# and click the OK button.
  9. This will open the 4DK# resource for editing similar to other STR# lists.


Now you can create your own constants in this STR# listing. To begin creating them:


  • Click where it reads 1) ***** and chose "Insert New Field(s) from the Resource menu.
  • Type in your constant information where it reads "The string"
  • Use the following format: Constant Name:Value:Type
    Example: Tax Rate:.0825:R


Although you could possibly create your own constants in version 6.0.x, 4D Compiler would not recognize them. Now the compiler version 6.5 will recognize and compile correctly.