• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
      • Introduction to CSPro Language
      • Data Requirements
      • CSPro Program Structure
      • Programming Standards
      • Code Folding
      • Debugging CSPro Applications
      • Declaration Section
      • Procedural Sections
      • Logic
      • Language Elements
        • Version
        • Delimiters
        • Comments
        • Preprocessor
        • Variables and Constants
        • Expressions
        • Operators
        • Files
        • Miscellaneous
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Logic Preprocessor

Format
#if condition
#
elseif condition
#
else
#
endif
Description
Before CSPro logic is compiled, it passes through a preprocessor that allows you to conditionally compile your code based on certain conditions. This is an advanced feature and is primarily useful when using external logic files where certain functionality may only successfully compile based on characteristics of the application.
The preprocessor uses the language's familiar if/elseif/else/endif keywords but with four differences:
  1. The keyword must be preceded by a # character.
  2. The # must be the first non-whitespace character on the line.
  3. The whole condition must be specified on a single line.
  4. A condition should not end with a then keyword.
An #if and #endif pair must exist, and optionally #elseif and #else can be included as part of a preprocessor block.
Conditional Functionality
The preprocessor is activated before the rest of logic is compiled and thus has limited functionality. Simple math expressions and conditional checks are possible, and there are two functions that can be called as part of conditional checks:
AppType(app_type)
This function returns true if your application is of the type specified by app_type. Supported types are Entry, Batch, and Tabulation.
exists(symbol_name)
This function returns true if a symbol exists at compile-time. The function checks for symbols that exist as part of an application (dictionary names, form names, etc.), and not symbols that are created during compilation (user-defined functions, objects, etc.).
Other Functionality
Another function can be used to set properties for the application, or for objects:
#setProperty(ʃobject_name,ʅ property_name, property_value);
Currently this function is only used to modify the case read optimization.
Example 1
function string GetEAName(numeric province, numeric district, numeric ea)

   
string ea_name = maketext("EA %04d-%02d-%03d", province, district, ea);

   
// if we have access to the geocodes dictionary, add the EA description to the name
#if exists(GEOCODES_DICT)

    GEOCODES_PROVINCE = province;
    GEOCODES_DISTRICT = district;
    GEOCODES_EA = ea;

   
if loadcase(GEOCODES_DICT, GEOCODES_PROVINCE, GEOCODES_DISTRICT, GEOCODES_EA) then
        ea_name = ea_name + 
" / " + strip(EA_DESCRIPTION));
   
endif;

#
endif

   
exit ea_name;

end;
Example 2
function ValidateLiteracy()

   
if HH_EDUCATION in 3:6 and HH_LITERACY <> 1 then

#
if AppType(Entry)
       
errmsg("Person with education level %d should be literate. Please correct.", HH_EDUCATION);
       
reenter;

#
elseif AppType(Batch)
       
errmsg("Person with education level %d should be literate. Literacy imputed to 1 (literate).", HH_EDUCATION);
       
impute(HH_LITERACY, 1);

#
endif

   
endif;

end;