I did a fair amount of research on this issue but can't get my head around a solution. Here's the problem:
Using HP UFT I read a column value from an ADO recordset with Vbscript. This column is a decimal(18,3) and vbScript recognises the decimal datatype (VarType).
Retrieving the value to vbScript results in a VbDouble variable with precision 15. Thus losing the decimal places.
Can anyone help me to retrieve all 18 digits?
My code & what I tried: In below code I read the recordset value and created portions that attempt to resolve this. None of them work.
Dim OdbcDSN
Dim connect, sql, resultSet
OdbcDSN = "DSN=CLAV;UID=UFT;PWD=UFT"
Set connect = CreateObject("ADODB.Connection")
connect.Open OdbcDSN
sql="select Mfr0335BtrTrxBdr from MFR0335"
'--> contains 123456789012345.123
Set resultSet = connect.Execute(sql)
On Error Resume Next
resultSet.MoveFirst
wscript.echo "getstring: " & resultSet.getstring()
'--> 123456789012345
resultSet.MoveFirst
With resultSet.fields.item("Mfr0335BtrTrxBdr")
wscript.echo "-------value & type -------------"
wscript.echo .value
'--> 123456789012345
wscript.echo "datatype rs column = " & .type
'--> 131 (adNumeric ADO datatype)
wscript.echo "datatype read by vbscript = " & vartype(.value)
'--> 14 (VbDecimal)
wscript.echo "length = " & len(.value)
'--> 15
wscript.echo "------- conversion -------------"
wscript.echo "cStr: " & cstr(.value)
'--> 123456789012345
wscript.echo "formatnumber: " & formatnumber(.value, 3, 0, 0, 0)
'--> 123456789012345.000
wscript.echo "-------assign value to variable ------"
myVar = .value
wscript.echo "myVar: " & myVar
'--> 123456789012345
wscript.echo "vartype: " & vartype(myVar)
'--> VbDouble
wscript.echo "-------convert Vbdecimal to string?----"
err.clear
myVar = cstr(.value)
wscript.echo "vartype: " & vartype(myVar)
'--> 8 (VbString)
wscript.echo "myVar: " & (myVar)
'--> 123456789012345
wscript.echo "-------is equal to it's decimal value?---"
err.clear
wscript.echo .value = 123456789012345.123
'--> (no value)
wscript.echo err.description
'--> Type mismatch
wscript.echo vartype(123456789012345.123)
'--> VbDouble
wscript.echo "--------do calculation with decimal values-----"
err.clear
wscript.echo 123456789012345.123 - 123000000000000.0
'--> 456789012345.125
wscript.echo vartype(123456789012345.123 - 123000000000000.0)
'--> Vbdouble
resultSet.MoveNext
end with
resultSet.Close
connect.Close
Set connect = Nothing
WScript.Quit(0)
output:
getstring: 123456789012345
-------value & type -------------
123456789012345
datatype rs column = 131
datatype read by vbscript = 14
length = 15
------- conversion -------------
cStr: 123456789012345
formatnumber: 123456789012345.000
-------assign value to variable ------
myVar: 123456789012345
vartype: 14
-------convert Vbdecimal to string?----
vartype: 8
myVar: 123456789012345
-------is equal to it's decimal value?---
Type mismatch
5
--------do calculation with decimal values-----
456789012345.125
5