I am using Xojo 2022r4.1 with MacOS 13.4.1 and code from Xojo API1.
I am having an issue with adding values from a RecordSet from a Postgres 10.4 database.
For example, if I have a table transactions with the following columns:
charge float8
paid float8
credits float8
and a row with the following values:
Charge
Paid
10
10
the following gives the the wrong answer.
dim s as String
dim rs as RecordSet
//Search record here
s = Str(rs.Field("paid").Value +rs.Field("credits").Value ,"###,##0.00")
The value returned for s is: 1,010.00
//Not 20.00
There are numerous instances in this project where values from the database are added using .value and I am wondering if there is something with the way this code is formatted causes the error.
// rs is a RecordSet with a double column called “InterestRate” Dim interestRate AsDouble
interestRate = rs.Field(“InterestRate”).Value // Converts from a Variant to a Double
I would suggest that the comment is misleading. No conversion is being done. IOW, a variant is not like Schroedinger’s Cat: it has a definite state (type) before you look at it. As you have this definition:
then .Value returns a Double for those columns. But it will return an integer if the column was defined as integer. So although a variant will actually convert if it can, this won’t work:
Var myvar as Variant, myint as Integer
myvar = new Dictionary
myint = myvar
Note that the compiler doesn’t pick this up; you get a runtime error.