When you define a structure, you are defining a new datatype. You can use this new datatype in scripts and user-defined functions as long as the structure definition is stored in a library in the application's library search path.
To use a structure in a script or user-defined
function:
Declare a variable of the structure type.
Reference the variable in the structure.
The variables in a structure are similar to the properties of a PowerBuilder object. To reference a global structure’s variable, use dot notation:
structure.variable
Example Assume that s_empdata is a global structure with the variables emp_id, emp_dept, emp_fname, emp_lname, and emp_salary. To use this structure definition, declare a variable of type s_empdata and use dot notation to reference the structure’s variables, as shown in the following script:
s_empdata lstr_emp1, lstr_emp2 // Declare 2 variables
// of type emp_data.
lstr_emp1.emp_id = 100 // Assign values to the
lstr_emp1.emp_dept = 200 // structure variables.
lstr_emp1.emp_fname = "John"
lstr_emp1.emp_lname = "Paul-Jones"
lstr_emp1.emp_salary = 99908.23
// Retrieve the value of a structure variable.
lstr_emp2.emp_salary = lstr_emp1.emp_salary * 1.05
// Use a structure variable in a
// PowerScript function.
MessageBox ("New Salary", &
String(lstr_emp2.emp_salary,"$###,##0.00"))
You reference object-level structures in scripts for the object itself exactly as you do global structures: declare a variable of the structure type, then use dot notation:
structure.variable
Example Assume that the structure str_custdata is defined for the window w_history and you are writing a script for a CommandButton in the window. To use the structure definition in the script, you write:
str_custdata lstr_cust1 lstr_cust1.name = "Joe"