Tech Tip: Finding the number of characters containing a alpha text and text field of a record
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: May 25, 2018
Here is a utility method that will find the total number of characters in a record that contains the alpha text and text fields:
// ---------------------------------------------------------------------- // Name: CHAR_TOTAL_ALPHA_TEXT_FIELDS // Description: Method will extract the total count of characters in the // alpha text and text fields of a record. // // Parameters: // $1 (POINTER) - Pointer to the table // Output: // $0 (LONGINT) - Number of characters // ---------------------------------------------------------------------- C_POINTER($1;$table;$fieldPtr) C_LONGINT($i;$tableNum;$fields;$type;$totalChars) If (Count parameters=1) $table:=$1 $tableNum:=Table($table) $fields:=Get last field number($tableNum) $totalChars:=0 For ($i;1;$fields) $fieldPtr:=Field($tableNum;$i) $type:=Type($fieldPtr->) If (Is field number valid($tableNum;Field($fieldPtr))=True) If (($type=2) | ($type=0)) $totalChars:=$totalChars+Length($fieldPtr->) End if End if End for $0:=$totalChars End if |
Here is example of a field with some text:
Here is the utility method in use:
C_LONGINT($charCount) QUERY([Table_1];[Table_1]ID=1) $charCount:=CHAR_TOTAL_ALPHA_TEXT_FIELDS (->[Table_2]) // $charCount = 8 |