Python COM Servers and Excel/VBA: Set/Get multidimensional attributes...

Carl Johan Rehn carljohan.rehn at chello.se
Tue Aug 21 14:56:26 EDT 2001


Does anyone know how to set/get attributes in Python COM objects that are
multidimensional arrays (list of lists)?
Here is a short extract of code that I have been playing around with.

Yours, Carl

Python COM Server:

COMEXPOSE = 1
class RandomStockPrice:
        if COMEXPOSE == 1:
                _public_methods_ = [ '__init__', 'StockPrice' ]
                _public_attrs_ = [ 'l_S0', 'l_Sigma']
                _reg_progid_ = "Random.Stock"
                _reg_clsid_ = "{1EA514E2-954B-11D5-B564-0002A563A48C}"
        def __init__(self):
                # l_S0 and l_Sigma are multidimensional, i.e. list of lists
                self.l_S0 = []; self.l_Sigma = []
        def StockPrice(self):
                # Some code stuff...
                StockPrice = 0.0
                return StockPrice
if __name__=='__main__':
        if COMEXPOSE == 1:
                import win32com.server.register
                win32com.server.register.UseCommandLine(RandomStockPrice)
        else:
                RSP = RandomStockPrice()

Excel/VBA COM Client:

Sub COMRandomStockPrice()
    Set COMServer = CreateObject("Random.Stock")
    Dim l_S0 As Variant
    Dim l_Sigma As Variant
    l_S0 = Array(350#, 350#, 350#)
    l_Sigma = Array(Array(0.75, 0.7, 0.7), _
                                 Array(0.7, 0.75, 0.7), _
                                 Array(0.7, 0.7, 0.75))
    COMServer.l_S0 = l_S0
    COMServer.l_Sigma = l_Sigma
    Dim S As Variant
    Dim Sigma As Variant
    S = COMServer.l_S0
    Sigma = COMServer.l_Sigma
    Debug.Print S(0, 0)
    Debug.Print Sigma (0, 0)
End Sub





More information about the Python-list mailing list