1

When trying to convert responseText to a user-defined object, I get the error: Sub or Function not defined.

How do I convert a tuple sent by the server in responseText? Some previous posts suggested of casting using CType but VBA can't seem to find it and gives a compiler error.

Here's my code with the user-defined type that should be assigned the tuple in responseText. Thanks

Type DblStrTuple
    StrikePrice As Double
    Volatility As String
End Type

Function GetCorrectPutStrikeAndVolatility(ByVal StockTicker, ByVal StrikePrice, ByVal TargetDate) As DblStrTuple

    Dim XmlHttp As Object
    Set XmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    Url = "http://192.168.1.9:5005/options/get_strike_price_and_volatiitlity?"

    FinalUrl = Url & StockTicker & "+" & StrikePrice & "+" & TargetDate

    XmlHttp.Open "GET", FinalUrl, False

    XmlHttp.send

    CorrectCallOptionStrikePrice = DblStrTuple(XmlHttp.responseText)

End Function
Kostas K.
  • 8,293
  • 2
  • 22
  • 28
Gnosis
  • 11
  • 2
  • You're treating the `DblStrTuple` type like it's a function where you pass the `responseText` as parameter. You need another function to do the conversion. – Kostas K. Jun 19 '20 at 07:52
  • VBA does not have CType. That's a VB Net method. What is the format of the response text? Is it comma separated values? If so you could just convert the responsetext to an array using Split and store that array in a variant. – freeflow Jun 19 '20 at 08:27
  • The returned value is "[68.0, "43.95%"]". So it is comma-separated. But using Split generates a compile error: can't assign to array. VariantArray = Split(XmlHttp.responseText, ",") Any ideas? Thanks – Gnosis Jun 19 '20 at 15:35

0 Answers0