• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
        • Assignment Statement
        • Recode Statement
        • Recode Statement (Deprecated)
        • Impute Function
        • SetValue Function
        • GetValue Function
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization 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>

SetValue Function

Format
b = setvalue(variable_name, valueʃ, occurrence1, ..., occurrence3ʅ);
Description
The setvalue function executes an assignment when the name of the variable to be assigned to is not known at compilation time (when writing the application). The function searches for a variable with a name stored in the string expression variable_name, and if such a variable is found, the function assigns to it the value stored in value. If the variable is numeric, then value should be a numeric expression, and if the variable is alphanumeric, then it should be a string expression. Optional arguments, occurrence1 to occurrence3, allow you to pass occurrence numbers to the function. This function is especially useful when combined with a userbar button or an OnKey character sequence.
Return Value
The function returns a logical value of 1 (true) if the variable name was found and the value was successfully changed. The function returns 0 (false) if the variable was not found, if a string expression was assigned to a numeric variable, or if a numeric expression was assigned to an alphanumeric variable.
Examples
// the following statements are equivalent but you would not use setvalue
// because the left-hand side of the assignment is already known

setvalue("NAME", "Amelia");
NAME = 
"Amelia";

setvalue("AGE", 20);
AGE = 
20;

// below, the left-hand side of the assignment is not known at compilation time

setvalue(getsymbol(), missing); // set the current field to missing

setvalue(getsymbol(), "DK", 3); // set the third occurrence of the current field to "DK"
See also: GetValue Function, Assignment Statement