private StockLabel ,lastStockLabel
''''''''''''如下为绘图主函数
Sub Technic_Paint()
dim grid
Set grid = Technic.GetGridByName("Main")
dim count
dim StockLabel
count =grid.GetHistoryData().count
StockLabel=grid.StockLabel
if not( grid is nothing ) and lastStockLabel<>StockLabel and grid.IsWindow then
'当K线数量变化、证券品种变化、周期变化、新行情到来,重新计算行情数据
grid.CoordinateMode=1 '设置为对数坐标
grid.MustPower=1 '复权
grid.PowerAspect=0 '向前复权
tn=0 '当需要重新计算行情数据,将TN初始化为0
call Test
end if
lastStockLabel=grid.StockLabel
end sub
'调用VBA函数
sub Test
'创建外部对象,启用Python引擎
Set d = CreateObject("Stock.Python")
'载入Python模块,模块名为MyPython
ret = d.ImportModule("jzt_MyPython1")
If ret <> 1 Then
'载入失败,打印错误原因
Msg = d.GetErrorInfo()
Application.MsgOut Msg
Set Msg = Nothing'使用完毕需要 Set Nothing销毁以免出现内存泄漏
Exit Sub
End If
Data = d.CallObject("zhibiao_vba")'调用PY模块中的函数
If IsEmpty(Data) Then
Msg = d.GetErrorInfo()
Application.MsgOut Msg
Set Msg = Nothing'使用完毕需要 Set Nothing销毁以免出现内存泄漏
Exit Sub
End If
'打印返回值
application.MsgOut "Result:"&Data
Set d = nothing'使用完毕需要 Set Nothing销毁以免出现内存泄漏
end Sub
[此贴子已经被作者于2020/4/20 17:37:47编辑过]