Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
4th Dimension (software)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Syntax == This section will include syntax examples demonstrating different programming constructs used in 4D, such as for loops and variable usage. === Data Types === 4D fields, variables, and expressions can be of the following data types:<ref>{{cite web |title=Data Types |url=http://doc.4d.com/4Dv15R3/4D/15-R3/Data-Types.300-2695014.en.html |website=4D Doc Center |access-date=28 July 2022}}</ref> {| class="wikitable" |- ! Data Type ! Field ! Variable ! Expression |- |String |{{Yes}} |{{Yes}} |{{Yes}} |- | Number (double) | {{Yes}} | {{Yes}} | {{Yes}} |- | Date | {{Yes}} | {{Yes}} | {{Yes}} |- | Time |{{Yes}} |{{Yes}} |{{Yes}} |- | Boolean | {{Yes}} | {{Yes}} | {{Yes}} |- | Picture | {{Yes}} | {{Yes}} | {{Yes}} |- | Pointer | {{No}} | {{Yes}} | {{Yes}} |- | BLOB | {{Yes}} | {{Yes}} | {{No}} |- | Array | {{No}} | {{Yes}} | {{No}} |- | Integer 64 bits | {{Yes}} | {{No}} | {{No}} |- | Float | {{Yes}} | {{No}} | {{No}} |- | Object | {{Yes}} | {{Yes}} | {{Yes}} |- | Collection | {{Yes}} | {{Yes}} | {{Yes}} |- | Undefined | {{No}} | {{Yes}} | {{Yes}} |} More info on 4D data type can be found on the [ 4D Data Types] documentation page === Variable Scope === Local variables are prefixed with a <code>$</code> like <code>$myLocalVariable</code> and only live for the duration of the method. Process variables have no prefix like <code>myProcessVariable</code> and live throughout the duration of the process. Inter-process (or Global) variables are prefixed with a <code><></code> like <code><>myGlobalVariable</code> and live throughout the duration of the application. === Comparison of looping === ==== For ==== <pre> For(vCounter;1;100) // Do something End for </pre> ==== While ==== <pre> $i :=1 // Initialize the counter While($i<=100) // Loop 100 times // Do something $i :=$i +1 // Need to increment the counter End while </pre> ==== Repeat ==== <pre> $i :=1 // Initialize the counter Repeat // Do something $i :=$i +1 // Need to increment the counter Until($i=100) // Loop 100 times </pre> ==== Nested Loops ==== The following example goes through all the elements of a two-dimensional array: <pre> For($vlElem;1;Size of array(anArray)) // ... // Do something with the row // ... For($vlSubElem;1;Size of array(anArray{$vlElem})) // Do something with the element anArray{$vlElem}{$vlSubElem}:=... End for End for </pre> The following example builds an array of pointers to all the date fields present in the database: <pre> ARRAY POINTER($apDateFields;0) $vlElem:=0 For($vlTable;1;Get last table number) // loop over each table number with $vTable as the number If(Is table number valid($vlTable)) // check if table number $vTable is valid // only loop on the valid table For($vlField;1;Get last field number($vlTable)) // loop over each field number within current table // with $vlField as the current field number If(Is field number valid($vlTable;$vlField)) // check if field number is valid $vpField:=Field($vlTable;$vlField) // get pointer to field If(Type($vpField->)=Is date) // check if current field is a date // only performs these actions if field is a date $vlElem:=$vlElem+1 INSERT IN ARRAY($apDateFields;$vlElem) $apDateFields{$vlElem}:=$vpField End if End If End for End If End for </pre>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)