$lastmember

Returns the number of members in a result set.

Syntax

$lastmember(setname)

Parameters

setnameA character string or an expression that evaluates to a character string, being the name of a result set.

Return Value

Number with no decimal places.

Comments

$lastmember returns the (numerical) position of the last member in the specified result set (in effect telling you how many members the set contains). To explicitly specify the current set, use “CurrentSet”, including the quotation marks, as the function is expecting a character string, and CurrentSet is a reserved word.

To ensure against unexpected results, choose set names carefully. At run time, the software distinguishes sets only by their names, even if they are permanent set names created in different application directories.

If, for example, you produce a set called Set1 in directory PersonnelData, and later you produce another set called Set1 in directory TestData, the second version of Set1 replaces the first version. Function $lastmember works on only the most recent version of the set.

Example

To display the number of members in Set1, enter

output ($lastmember("Set1"))
25 % Displays the number of members in Set1.
procedure ProcessSet ()
   if $lastmember("EmpSet") = 0
      return
   endif
   ...more commands...
endprocedure

If a procedure processes a set created elsewhere, it is not necessary to pass the size of the set as a parameter; $lastmember can be used instead.

See Also

$currentmember

$SetCount

About Functional Expressions

{ } (Case) – Inline Case Expressions

Unlock the Power of Conditional Logic with Zim Case Expressions

Elevate your Zim application development with our powerful case expressions feature. Designed to streamline your coding process and enhance functionality, case expressions provide a robust solution for handling conditional values effortlessly.

Key Benefits:

  • Efficient Coding: Simplify your code with concise case expressions, reducing complexity and improving readability.
  • Reliable Value Assignment: Ensure non-null values in critical operations, preventing errors and enhancing application stability.
  • Dynamic Adjustments: Implement dynamic logic that adapts to changing conditions, delivering flexible and responsive applications.
  • Graceful Handling of Missing Data: Provide fallback options for missing values, ensuring comprehensive and informative outputs.

Case Expressions in Zim

Syntax:

{ expression1 , expression2 }

Parameters:

  • expression1: Any value expression.
  • expression2: Any value expression.

Return Value:

  • The value of the first expression that is not $Null.

Technical Expansion:

Evaluation Process:

  • Sequential Evaluation: The expressions within the braces are evaluated from left to right. This ensures that the first non-null value is selected, providing a reliable mechanism for conditional value assignment.
  • Nested Expressions: Case expressions can be nested, allowing for complex conditional logic to be handled efficiently. This is particularly useful in scenarios where multiple conditions need to be evaluated in sequence.

Usage Scenarios:

  • Conditional Value Assignment: Case expressions are ideal for assigning values based on conditions. For example, determining a status based on height:
  let Status = {'tall' where Height > 6, 'short'}

This simplifies the code and ensures that the correct status is assigned based on the height condition.

  • Ensuring Non-Null Values: In situations where a field or widget might be $Null, case expressions can provide a default value, ensuring that operations proceed smoothly:
  let Salary = {fAddEmps.Salary, 0}
  • Dynamic Action Determination: Case expressions can be used to determine actions based on conditions, such as adjusting a year based on the month:
  break 1
    {$year(InvDate) + 1 where $month(InvDate) >= 5, $year(InvDate)}
    heading ...
  • Handling Missing Values: In reports or outputs, case expressions can handle missing values gracefully, providing a fallback option:
  detail line "Employee Number: " {EmpNum, "N/A"}

Advanced Features:

  • Platform Independence: Case expressions are versatile and can be used across different platforms, ensuring consistent behavior in various environments.
  • Performance Optimization: By minimizing the code required for conditional logic, case expressions can improve the performance of applications, reducing processing time and resource usage.

Experience the Difference: Transform your Zim applications with the efficiency and reliability of case expressions. Whether you’re streamlining conditional logic, ensuring non-null values, or handling dynamic adjustments, our case expressions feature is your key to superior development.

$center (or $centre)

Centers a non-blank character string.

Syntax

$center(string) | $centre(string)

Parameters

stringa character string, or an expression that evaluates to a character string

Return Value

Character string, consisting of string centered in a space $length(string) characters long. Leading or trailing blanks in string are ignored during centering. If string contains an odd number of characters, it centers with a bias to the left.

Comments

String is centered in an area that is $length(string) characters long. All leading and trailing blanks in string are ignored. If string contains an odd number of characters, the string is centered with a bias to the left.

Example

$center("abcde ")

Evaluates to ” abcde “. Centering five characters in a 10-character field produces a string that contains two spaces on the left and three spaces on the right.

$center(var3)

Evaluates to ” 3 “. If var3 is an INT variable whose value is 3, the resulting value is a string of eight characters, with three spaces to the left of the 3 and four spaces to the right. (INT values occupy eight character spaces when converted to character strings.)

See Also

$leftjustify

$length

$rightjustify

About Character Literals

About Data Types

About Functional Expressions

$addmonths

Calculates a date value by adding months to (or subtracting months from) a specified date value.

Syntax

$addmonths(date,number)

where

datea date, or an expression that evaluates to a DATE data type
numbera number, or an expression that evaluates to a number

Return Value

Number, representing a DATE value.

Comments

Use $addmonths to perform arithmetic with date values. The $addmonths function calculates a date value by adding a number representing months to a date value. If number is negative, the effect is to subtract the months from the date.

The + (add) and – (subtract) operators can be used to achieve the same results.

If date or the result of the $addmonths expression is an invalid date (e.g., 19930231), it is adjusted to produce a valid date (e.g., 19930228).

Example

If $Date has the value 19981225, then:

$addmonths($date,3)

Evaluates to 19990325.

$addmonths($date,-3)

Evaluates to 19980925.

$addmonths($date,20)

Evaluates to 20000825.

$addmonths(19980131,1)

Evaluates to 19980228 (note truncation).

See Also

$adddays

$addweeks

$addyears

$day

$dayname

$todate

$weekday

+ (Add/Positive)

About Functional Expressions

Arithmetic with Dates

PARSE

Tests a single Zim command, or an application program, for syntactic and semantic accuracy.

Syntax

PARSE commandstring | docname

Parameters

commandstringAny character string, enclosed in quotation marks, that represents a Zim command to be parsed.
docnameThe name of an application document that contains an application program to be parsed.

Comments

The PARSE command enables you to check an individual command or an entire program without executing either the command or the program. Executing a PARSE command does not affect any data values held either in memory or in the database. The PARSE command reports any syntactic or semantic irregularities that the PARSE command uncovers.

The sets created by FIND commands in parsed programs are defined. Only the directories accessed at the time that the PARSE command is executed are used. The ACCESS and RELEASE commands are parsed but not executed.

A program is parsed on a line-by-line basis. A program called from the program being parsed is not parsed, but the software does check to see if the program exists. All parts of commands with conditions are parsed, regardless of the validity of the conditions or the presence of any BREAK, CONTINUE, or TRANSFORM command.

Example

To check a command before running it, use

parse “list all Employees where LastName = Smith”

If you have an application program MyProg that calls the program SubUserCom, enter

parse MyProg

Only the command statements in MyProg are parsed. The software checks that SubUserCom exists, but does not parse it.

See Also

COMPILE

DEPENDENCY

GENERATE

LET

Assigns a value to a variable object.

Syntax

LET expression

Parameters

targetA global or local variable, a form field or menu item, a parameter, or a macro can be used. Subscripted (array) variables are valid.
expressionAny value expression.
The value of expression is assigned to target. Expression can include literals, constants, global or local variables, form fields, menu items, parameters, or fields in the current set. These objects can be combined using any of the arithmetic operators and functions.

Comments

The LET command is used to assign values to variable objects. To assign values to a field in an EntitySet or relationship, you must use ADD, CHANGE, INSERT, or UPDATE (which can contain a LET subcommand). The LET command is not used to assign values to database fields.

An assignment expression is formed by enclosing the LET command in parentheses.

If expression evaluates to $Null and target is a macro, the macro is assigned the null string. (A null string is a string of zero length, which is not the same as the $Null property.)

Example

let var1[1]=1 var1[2]=2 var1[3]=3

let var1 = $Date var2 = $tolower(LastName) var3[2] = 123

An example of using LET to assign values to variables.

let = “where LastName = Smith”

let= “from terminal prompt”

let <5> = $null

An example of using LET to assign values to macros.

See Also

Macros

ADD

CHANGE

How To Use Variables

INSERT

SET QUOTING

UPDATE

WHERE

[NOT] BETWEEN

Compares one value to a specified range of values.

Syntax

expression [NOT] BETWEEN expr1 AND expr2

Parameters

expressionAn expression that evaluates to either a number or a character string.
expr1An expression that evaluates to either a number or a character string.
expr2An expression that evaluates to either a number or a character string.

Return Value

Logical

Comments

If any one of expression, expr1, and expr2 is a number, then a numeric comparison is made; otherwise, the comparison is character-based. Note that the AND in a BETWEEN comparison is not the Boolean AND.

A BETWEEN comparison is logically true if expression is greater than or equal to expr1, and less than or equal to expr2.

A NOT BETWEEN comparison is logically true if expression is either less than expr1, or greater than expr2.

Note: The AND in a BETWEEN comparison is not the Boolean AND.

Example

BioDiversity between 500 and 2000

Logically true if the value of BioDiversity lies between 500 and 2000 (inclusive).

See Also

About Conditional Expressions

$InTransaction

Indicates if an explicit transaction is in progress.

Syntax

$intransaction

Return Value

“1” ($True), or “0” ($False). Can be reset by an application program.

Description

$InTransaction acts as a flag, indicating if the software is currently processing an explicit transaction.

$InTransaction is set to “1” ($True) if a TRANSACTION (or BEGIN WORK) command has started an explicit transaction. It is set to “0” ($False) when an ENDTRANSACTION or QUITTRANSACTION (or COMMIT WORK or ROLLBACK WORK) command has closed the explicit transaction in progress.

The variable is unaffected by deadlock or implicit transactions.

Example

on deadlock
   if $intransaction = $true
      goto RetryAdd
   else
      goto previous
   endif
endon
   ... other commands ...
RetryAdd:
   transaction
   ... commands in the transaction ...
   endtransaction

In the above example, when a deadlock occurs, $InTransaction determines the course of action that the exception handler takes: restart the explicit transaction (when true) or retry the command that caused the deadlock (when false).

procedure UpdateCode (NewCode) local (DoEndTrans)
   if $intransaction = $false
      transaction
      let DoEndTrans = $true
   endif
   ... other commands ...
   if DoEndTrans = $true
      endtransaction
   endif
endprocedure

In the above example, $InTransaction starts an explicit transaction if one is not already in progress.

See Also

BEGIN WORK

COMMIT WORK

GOTO

GOTO NEXT

GOTO PREVIOUS

ON

QUITTRANSACTION

ROLLBACK WORK

System Variables

COMPUTE

Computes the results of one or more expressions for a set of records.

Syntax

COMPUTE [num] [setspec] EVALUATE clause [-> clause]

Parameters

num

Can be
an integer constant (15, 200);
a variable, form field, or parameter that evaluates to an integer;
the word ALL.
If num is omitted, or less than 0, it defaults to ALL.

setspec

The set specification (made up of application documents, EntitySets, relationships, forms, or result sets), designating the records to be changed. If omitted, the current set (if available) is used.
Application documents named in the set specification cannot be updated.

Comments

COMPUTE evaluates one or more expressions for a set of records without having to first LIST the data or create a result set of the desired records.

Example

Compute all Employees where LName=Smith \

evaluate \

(let TotSal = $total(Salary)) \

(let MaxSal = $max(Salary)) \

(let MinSal = $min(Salary)) \

(let NoOfEmps = $count(LName)) \

(let AvgSal = $average (Salary))

output TotSal MaxSal MinSal NoOfEmps AvgSal

Processes the EVALUATE clause for every employee whose last name is “Smith”. The OUTPUT command displays the results.

form open dInvoice

form display input

compute fInvItems evaluate (let fInvBott.InvTot = $total(fInvItems.Amt))

form display fInvBott.InvTot

Calls up a display and calculates a total after all items have been added.

 

See Also

$MEMBERCOUNT

FIND

INPUT

Gets serial input from the application user.

Syntax

INPUT «target»

Parameters

targetA list of one or more global or local variables, form fields, menu items, parameters, or macros, in any combination. Subscripted (array) variables are valid. Each item must be separated from the next by a space.

Comments

INPUT provides a simple means of reading a line of input from the application user. The line of input is divided into literal strings based on the delimiter character currently in effect. The literals are assigned to the variables and macros specified in target, in order from left to right.

Example

input TestVar fEmpform.LastName Param1 < CommandName> <3>

When the above command pauses for input, the following constants can be input by the application user:

32 Smith abc LIST abc_def

If current delimiter is the space character, the constants are assigned as follows:

TestVar32
fEmpform.LastNameSmith
Param1abc
#< CommandName>LIST
#<3>abc_def

The following sequence of entries accomplishes the same effect, but uses the comma as the delimiter:

set delimiter “,”

input TestVar fEmpform.LastName Param1 < CommandName> <3>

32,Smith, abc,LIST, abc_def

Attention

When using the following construction, a “:” must be placed at the end of the OUTPUT string:

OUTPUT “Please, respond with Yes or No (Y/N): “;

input vResponse

See Also

SET DELIMITER

OUTPUT

en_CAEnglish