等级: 新手上路
- 注册:
- 2022-3-8
- 曾用名:
|
我目标是这样的,我需要从一个数据库表中分别读出股票代码(PINZHONG)、对应的市场SH或SZ(SHICHANG)、当时日期(tbDATE)。再读取MarketData.GetHistoryData对象,获取历史数据。再分别得到该代码的今日CLOSE和当时的CLOSE,做一些分析用。代码如下:
Sub GetHistoryDAT()
Dim d1 '创建一个变量
DIM DATA1
dim jiage,jtjiage
dim tday,s,sweiz
dim riqi,jiange
dim jintian,lastday
dim strSqlread,rstTmp,adoConn,aapz,aasc,aaid,aadate
Set adoConn=CreateObject("Adodb.Connection")
adoConn.Open"Provider=MicroSoft.ACE.OLEDB.12.0;Data Source=d:\trader\temp\PTproTable.accdb"
'创建Array外部对象,将对象实例置变量d中
Set d1 = CreateObject("Stock.Array")
strSqlread="select * from B16最底1 where tbDATE =#2022/03/16# "
'ADO Recordset 对象用于容纳一个来自数据库表的记录集。
Set rstTmp=CreateObject("ADODB.RecordSet")
rstTmp.open strSqlread,adoConn
marketdata.HistoryDataMode=1
s=0
DO WHILE rstTmp.EOF=FALSE
aasc=rstTmp("SHICHANG")
aapz=rstTmp("PINZHONG")
aaid=rstTmp("tbID")
aadate=rstTmp("tbDATE")
Set Data1= MarketData.GetHistoryData(aasc,aapz,5)
call application.MsgOut("品种" & aapz & "市场" & aasc & "计数" & aaid & "日期" &aadate )
jintian=date
lastday=CDate("2022/3/16")
jiange=jintian-lastday
tday=Data1.count
riqi=Data1.date(tday-1)
jiage=Data1.close(lastday)
jtjiage=Data1.close(riqi)
rstTmp.MoveNext
Set d1 = nothing '释放对象
Set data1 = nothing
s=s+1
marketdata.DestroyHistoryData
LOOP
set rstTmp =nothing
set strSqlread= nothing
adoConn.close
set adoConn=nothing
'MsgBox "品种" & aapz & "当时价格" & jiage & "今天价格" & jtjiage
End Sub
|
|