以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  如何生成与品种对应的文本文件名?  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=7951)

--  作者:hs6932
--  发布时间:2011/9/9 10:05:22
--  如何生成与品种对应的文本文件名?

我的代码如下:

Dim fso, txtf
FileName="F:\\SIGTrader\\experts\\files\\ STKNAME()" &".txt"
Set fso = CreateObject("Scripting.FileSystemObject")
set txtf=fso.createtextfile(filename,true)

 

这样生成的文件名总不是品种的相应代码,请高手指点


--  作者:阿火
--  发布时间:2011/9/9 10:31:55
--  

你又没有获取品种代码

可用grid对象获取品种代码或者名称


--  作者:hs6932
--  发布时间:2011/9/9 12:56:44
--  

不明白如何使用grid,请老大帮我修改一下代码啊。多谢!

我的源码如下:

参数N为 600

 

ao:=o; ah:=h; al:=l; ac:c; av:=vol; amo:=amount;
y:=year; m:=month; d:=day; na:=STKLABEL; mc:=STKNAME();
<%
bo=ffl.vardata("ao")
bh=ffl.vardata("ah")
bl=ffl.vardata("al")
bc=ffl.vardata("ac")
bv=ffl.vardata("av")
bmo=ffl.vardata("amo")
by=ffl.vardata("y")
bm=ffl.vardata("m")
bd=ffl.vardata("d")
bna=ffl.vardata("na")
bmc=ffl.vardata("mc")
bn=ffl.vardata("n")

u=ubound(bo)

for i=0 to u-1
by(i)=0
bm(i)=0
bd(i)=0
next
by(u)=year(date):bm(u)=month(date):bd(u)=day(date)

yy=by(u)
mm=bm(u)
dd=bd(u)

for i=u-1 to 0 step -1
ss=cstr(bm(i+1)) &"/"& cstr(bd(i+1)) &"/" &cstr(by(i+1))
sh=dateadd("d",-1,ss)
if weekday(ss)=2 then sh=dateadd("d",-3,ss) end if

by(i)=year(sh)
bm(i)=month(sh)
bd(i)=day(sh)


nn=bn*100
nnn=u-nn
if (nnn<0 or nnn=u) then nnn=0 end if
next
Dim fso, txtf
FileName="F:\\SIGTrader\\experts\\files\\"&bmc & ".txt"
Set fso = CreateObject("Scripting.FileSystemObject")
set txtf=fso.createtextfile(filename,true)
for i=nnn to u
 tr0=cstr(bm(i))
if bm(i)<10 then tr0="0"&cstr(bm(i)) end if
 tr1=cstr(bd(i))
if bd(i)<10 then tr1="0"&cstr(bd(i)) end if
tr2= ""& cstr(by(i))&""& tr0 &""& tr1 &""
 tr=tr2&","&cstr(round(bo(i)*10000)/10000)&","& cstr(round(bh(i)*10000)/10000)& ","&cstr(round(bl(i)*10000)/10000)& ","&cstr(round(bc(i)*10000)/10000)& ","&cstr(round(bv(i)*10000)/10000)& ","&cstr(round(bmo(i)*10000/10000))
 txtf.WriteLine(tr)
next
txtf.Close
%>


--  作者:王锋
--  发布时间:2011/9/9 13:04:39
--  
bna=ffl.StrVarData("na")
bmc=ffl.StrVarData("mc")

--  作者:guotx2010
--  发布时间:2011/9/9 16:30:14
--  
vba公式中不能传递字符串的。
--  作者:guotx2010
--  发布时间:2011/9/9 16:39:37
--  

使用VBA后台程序,不是在公式中使用vba,方式是

1、公式中使用EXTGBSTRINGSET(\'品种\',stklabel)将品种代码写到全局字符串变量

2、在VBA模块中,使用aa=Document.GetExtString("品种")取出全局变量

3、后面的建立文件都可以在vba模块完成。

 

可以使用同样的方法将需要写入文件的数据先送到全局变量,然后在vba模块实现写文件,对于数值性数据,公式中使用EXTGBDATASET存入,

vba模块中使用document.getExtData("变量名")获取。