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.
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 |
string stringval<br>double dblval<br>date dateval<br>any anyval<br> <br>anyval = myoleobject.application.cells[1,1].value<br>CHOOSE CASE ClassName(anyval)<br>   CASE "string"<br>      stringval = anyval<br>   CASE "double"<br>      dblval = anyval<br>   CASE "datetime"<br>      dateval = Date(anyval)<br>END CHOOSE |