Automation and the Any datatype
Because PowerBuilder knows nothing about the commands and
functions of the server application, it also knows nothing about the
datatypes of returned information when it compiles a program.
Expressions that access properties and call functions have a datatype of
Any. You can assign the expression to an Any variable, which avoids
datatype conversion errors.
During execution, when data is assigned to the variable, it
temporarily takes the datatype of the value. You can use the
ClassName function to determine the datatype of the Any variable and
make appropriate assignments. If you make an incompatible assignment
with mismatched datatypes, you will get a runtime error.
Do not use the Any datatype unnecessarily
If you know the datatype of data returned by a server automation
function, do not use the Any datatype. You can assign returned data
directly to a variable of the correct type.
The following sample code retrieves a value from Excel and assigns
it to the appropriate PowerBuilder variable, depending on the value’s
datatype. (For an Excel 95 spreadsheet, the row and column arguments for
cells are in parentheses instead of square brackets.)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
string stringval double dblval date dateval any anyval anyval = myoleobject.application.cells[1,1].value CHOOSE CASE ClassName(anyval) CASE "string" stringval = anyval CASE "double" dblval = anyval CASE "datetime" dateval = Date(anyval) END CHOOSE |