question

Upvotes
Accepted
3 0 0 0

Type Mismatch VBA - DfAddPeriod

Hello,

I am trying to use DfAddPeriod in VBA :


Public Function CreateAdxDateModule() As AdfinXAnalyticsFunctions.AdxDateModule
    Set CreateAdxDateModule = CreateReutersObject("AdfinXAnalyticsFunctions.AdxDateModule")
End Function


CreateAdxDateModule.DfAddPeriod("FRA", "12/02/2021", "1M", "EMC:S")

But this does return a Type Mismatch error, what Am I doing Wrong ?
Kindly

eikoneikon-com-apivbadate
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

1 Answer

Upvotes
Accepted
39.2k 75 11 27

Most likely you have a type mismatch in the assignment statement calling CreateAdxDateModule.DfAddPeriod("FRA", "12/02/2021", "1M", "EMC:S") expression. The above function returns a Variant(1 To 1, 1 To 2) array. How do you declare the variable you assign the result of CreateAdxDateModule.DfAddPeriod("FRA", "12/02/2021", "1M", "EMC:S") to? In other words in the statement below how do you declare the variable named "res"?

res = CreateAdxDateModule.DfAddPeriod("FRA", "12/02/2021", "1M", "EMC:S")

On a side note, rather than creating a public function that returns AdxDateModule object (which in your example is named CreateAdxDateModule), I would suggest declaring a variable at the module level to store an instance of AdxDateModule class. This way you only need to have one instance of this class, which you can access any time you need to call a method like DfAddPeriod, rather than creating a new instance of AdxDateModule every time you execute DfAddPeriod method. E.g.

Dim m_AdxDateModule As AdfinXAnalyticsFunctions.AdxDateModule
Private Declare Function CreateReutersObject Lib "PLVbaApis.dll" (ByVal progID As String) As Object

Sub Test()
Dim res As Variant
If m_AdxDateModule Is Nothing Then Set m_AdxDateModule = CreateReutersObject("AdfinXAnalyticsFunctions.AdxDateModule")
res = m_AdxDateModule.DfAddPeriod("FRA", "12/02/2021", "1M", "EMC:S")
Debug.Print res(1, 1) & ", " & res(1, 2)
End Sub
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea