I use CallByName in a specific application and get results that I cannot explain. They are reproduced in a simple test with the following conditions.
- The class object property is of type Double Double
- The added value (Let) comes from a variant of the array that has been set to a range of several cells
I would appreciate an explanation of this behavior. The following code should reproduce it (at least in Excel 2007 / Windows 7)
A1 worksheet cell contains 5.8
A2 contains 1.3 , and the remaining cells in column A are empty.
Class module (class1)
Private pMyData Public Property Get MyData() MyData = pMyData End Property Public Property Let MyData(Value) pMyData = Value End Property
Regular module
Option Explicit Sub foo() Dim class1 As class1 Dim V(1 To 2, 1 To 1) As Variant V(1, 1) = [a1] V(2, 1) = [a2] Set class1 = New class1 CallByName class1, "MyData", VbLet, V(1, 1) Debug.Print V(1, 1), class1.MyData ' <-- 5.8 5.8 Dim W As Variant W = Range("A1:A2") Set class1 = New class1 CallByName class1, "MyData", VbLet, W(1, 1) Debug.Print W(1, 1), class1.MyData ' <-- 5.8 312080296 CallByName class1, "MyData", VbLet, CDbl(W(1, 1)) Debug.Print W(1, 1), class1.MyData ' <-- 5.8 5.8 End Sub
Note that the second line of debug.print shows that the value stored in class1.MyData is 312080296, not 5.8.
source share