Hi Peter,
DKNP wrote:
Having drilled down a bit further into the way the linked function works, The GetValueAt method works fine with strings (returns the value property), however with decimals it does not return the value property, it only returns the type (in this case BigDecimal).
It does return the value, not the type. The value is a BigDecimal instance and has all methods and properties of BigDecimal. It just does not have a property that contains the value, you'll need to use instance methods to get that value. E.g. you can use .doubleValue() to get the value as double.
DKNP wrote:
I have a table that contains numbers in currency format. When I use Table.FindRow with the row parameter set to the number or string I get "an unexpected error."
Using FindRow with BigDecimals is tricky. I guess FindRow uses something like .equals() or .compareTo() internally, so you'll need to create a BigDecimal that represents the sought-for value - so that the sought-for value is of the same type as the column. Here's how you can do this:
' Returns a BigDecimal corresponding to the specified string representation.
' Parameters:
' javaw - The application's java or javaw process, e.g. Sys.Process("javaw")
' str - the value as a string, e.g. "15.98"
' Return value:
' A java.math.BigDecimal object with the specified value
Function newBigDecimalFromString(javaw, str)
Dim jApi : Set jApi = javaw.JavaRuntime().JavaClasses
Set newBigDecimalFromString = jApi.java_math.BigDecimal.newInstance_4(str)
End Function
Then you can use:
Dim javaw : Set javaw = Sys.Process("javaw")
...
Dim value : Set value = newBigDecimalFromString(javaw, "15.98")
row = table.FindRow("Price", value)
But it's still tricky. You'll need to know the exact BigDecimal value, whereas the grid could display rounded values. There're also precision issues, so BigDecimal("15.98") != BigDecimal(15.98), because the latter may actually be 15.98000001.
A better approach could be to search the column manually for the displayed value, which brings us back to the getRenderedValue() function that you mentioned. I tried it with one sample app and it worked fine, so I'm not sure what might be wrong. From your mention of "Set" I assume you are using VBScript -- can you try this version instead?
Function getRenderedValue(table, row, column)
Dim value
If aqObject.GetVarType(table.getValueAt(row, column)) = varDispatch Then
Set value = table.getValueAt(row, column)
Else
value = table.getValueAt(row, column)
End If
Set renderer = table.getCellRenderer(row, column).getTableCellRendererComponent(table, value, False, False, row, column)
If aqObject.IsSupported(renderer, "getText") Then
value = renderer.getText().OleValue
End If
' Try to convert the resulting value to a primitive (e.g. java.lang.String -> plain string).
' If not possible, return the object value as is.
On Error Resume Next
getRenderedValue = value
If Err.Number <> 0 Then
Set getRenderedValue = value
Err.Clear
End If
End Function
If this works, you could perform the search like this:
row = -1
strValue = "$15.98"
For i = 0 To table.wRowCount
If getRenderedValue(table, i, 2) = strValue Then
row = i
Exit For
End If
Next
If row <> -1 Then
' Found
Else
' Not found
End If
Let us know if this helps.