I have been using CallByName in a particular application and getting results which I cannot explain. They are reproducible on a simple test with the following conditions
- The property of the class object is of Type Double
- The value being added (Let) comes from a variant array that has been set to a multiple cell range
I would appreciate an explanation for this behavior. The following code should reproduce it (at least in Excel 2007 / Windows 7)
Worksheet Cell A1 contains 5.8
A2 contains 1.3 and the rest of the cells in column A are blank.
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 the 2nd debug.print line shows that the value stored in class1.MyData is 312080296 and not 5.8.