Programming Guide : Creating Dynamic Frames : How You Can Manipulate Data in Dynamic Fields : How You Can Set and Get Simple Field Values
 
Share this page          
How You Can Set and Get Simple Field Values
OpenROAD provides the following methods for manipulating data in simple dynamic fields:
SetFieldValue
GetFieldValue
For example, assume that the field is a dynamic entry field whose Name attribute has been set to salary. Moreover, assume you want to perform a simple calculation, equivalent to the following statement's multiplication of the value in a statically created field named salary:
salary = salary * 1.15;
The following lines of code perform the same operation as the previous one line of code:
status = efield.GetFieldValue(value =
    byref(dollars));
dollars = dollars * 1.15;
status = efield.SetFieldValue(value = dollars);
The first statement gets the value in the efield field and loads it into the dollars variable. The second line increases the value in the dollars variable by 15 percent. The last line sets the value of the efield field with the current value of the dollars variable, thus increasing the value of a field (efield) named salary by 15 percent.
The integer variable status in this example is set to ER_OK if the method is successful. If not, status contains a value indicating the error condition. A typical source of error is data type incompatibility between the field and the variable to which its value is being assigned.
You can access other attributes of the dynamic field by using the reference variable pointing to the field (in the same manner as accessing attributes of statically created fields). For example, you can access the character string displayed in an entry field by using the TextValue attribute, which contains the string representing the characters that the user or program has entered into the field.
In the case of a varchar field, the value of the TextValue attribute is equivalent to the field's value. For any other kind of field, such as an integer or money field, you must use a conversion function to obtain the field's value from the TextValue attribute.
For example, the following code converts the value of a TextValue attribute to money, multiplies it by 1.5, and puts it into the dollars variable:
dollars = money(efield.TextValue) * 1.5;
The following code converts the money value stored in the dollars variable to varchar and puts it into the TextValue attribute of the efield field:
efield.TextValue = varchar(dollars);
Note:  If the user erroneously enters characters that are incompatible with a field's data type, using type conversion functions in this way causes errors that may be difficult to trace.