我对这个问题进行了大量研究,但无法解决问题。这就是问题所在:
使用HP UFT我使用Vbscript从ADO记录集中读取列值。此列为十进制(18,3),vbScript识别十进制数据类型(VarType)。
检索vbScript的值会导致VbDouble变量的精度为15.因此会丢失小数位。
任何人都可以帮我检索所有18位数字吗?
我的代码&我试过的: 在下面的代码中,我读取记录集值并创建了试图解决此问题的部分。他们都没有工作。
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)
输出:
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