水晶报表中的语句语法错误--进来看看

minajo21 2003-03-10 10:29:20
有一个老的.rpt文件,里面有一个formula field,是将一个SQL中的datatime字段以"8/3/2002 03:47:11"这种形式显示在报表上。check formula text 没有错误,我现在在另一个新报表文件上想添加一个相同的formula,却报错,怎么回事?

代码如下:

StringVar dt:={Viewlog.viewlog_date_time};
'-->此处,等号后面报错:A string is required here

if dt[6 to 6]<>"0" and dt[9 to 9]<>"0" then dt:=dt[6 to 8]+dt[9 to 10]+"/"+dt[1 to 4]+dt[11 to 19]
else if dt[6 to 6]="0" and dt[9 to 9]<>"0" then dt:=" "+dt[7 to 8]+dt[9 to 10]+"/"+dt[1 to 4]+dt[11 to 19]
else if dt[6 to 6]<>"0" and dt[9 to 9]="0" then dt:=dt[6 to 8]+" "+dt[10 to 10]+"/"+dt[1 to 4]+dt[11 to 19]
else if dt[6 to 6]="0" and dt[9 to 9]="0" then dt:=" "+dt[7 to 8]+" "+dt[10 to 10]+"/"+dt[1 to 4]+dt[11 to 19];
dt

其中Viewlog.viewlog_date_time在SQL中是datetime型,我也考虑了是不是类型不匹配,但老的代码也是这样写的,且没有什么SQL语句里也没用CAST,CONVERT来转换过。百思不得其解,望高手指点一二,不胜感激!!
...全文
36 32 打赏 收藏 转发到动态 举报
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
minajo21 2003-03-14
  • 打赏
  • 举报
回复
没搞定!!

无奈结贴!
lxcc 2003-03-13
  • 打赏
  • 举报
回复
只有up
minajo21 2003-03-13
  • 打赏
  • 举报
回复
不是空值的问题,我只选is not null的也报这个错呀
minajo21 2003-03-13
  • 打赏
  • 举报
回复
怎么显示时间格式呀?
难道没人遇到过这种问题?
Sean918 2003-03-13
  • 打赏
  • 举报
回复
友情 UP !
minajo21 2003-03-12
  • 打赏
  • 举报
回复
可能是我有为空的字段
lxcc 2003-03-12
  • 打赏
  • 举报
回复
A subscript must be 1 and the length of string
这个错误可能是超出控件的索引值,比如listview控件如果引用或设置listitem或者subitem超出范围(比如只有5个subitem,而你要用第7个subitem)时,出这种错,我是猜测,仅提供参考。不知对你有用吗?
minajo21 2003-03-12
  • 打赏
  • 举报
回复
to kmcyz(阿成)
不行啊,check 是没有错误,可是运行起来报
"A subscript must be 1 and the length of string"
lxcc 2003-03-12
  • 打赏
  • 举报
回复

"" & 字段
的方式可以避免空值
kmcyz 2003-03-11
  • 打赏
  • 举报
回复
这样试试:

StringVar dt:=ToText({Viewlog.viewlog_date_time});

if dt[6 to 6]<>"0" and dt[9 to 9]<>"0" then dt:=dt[6 to 8]+dt[9 to 10]+"/"+dt[1 to 4]+dt[11 to 19]
else if dt[6 to 6]="0" and dt[9 to 9]<>"0" then dt:=" "+dt[7 to 8]+dt[9 to 10]+"/"+dt[1 to 4]+dt[11 to 19]
else if dt[6 to 6]<>"0" and dt[9 to 9]="0" then dt:=dt[6 to 8]+" "+dt[10 to 10]+"/"+dt[1 to 4]+dt[11 to 19]
else if dt[6 to 6]="0" and dt[9 to 9]="0" then dt:=" "+dt[7 to 8]+" "+dt[10 to 10]+"/"+dt[1 to 4]+dt[11 to 19];
dt
minajo21 2003-03-11
  • 打赏
  • 举报
回复
好几天了,真的没人知道怎么做?
online 2003-03-11
  • 打赏
  • 举报
回复
帮你up
minajo21 2003-03-10
  • 打赏
  • 举报
回复
哪位朋友crystal report用的比较熟,帮帮忙!!
minajo21 2003-03-10
  • 打赏
  • 举报
回复
没什么特殊的设置呀

有没有什么好的其他方法来实现这个功能呢?
lxcc 2003-03-10
  • 打赏
  • 举报
回复
报表控件有什么设置吗
minajo21 2003-03-10
  • 打赏
  • 举报
回复
还是不行啊,什么问题呢?
Cooly 2003-03-10
  • 打赏
  • 举报
回复
继续up~~~
minajo21 2003-03-10
  • 打赏
  • 举报
回复
版本应该是一样的

老的是现成的,人家写好的

sorry,我没说清楚
lxcc 2003-03-10
  • 打赏
  • 举报
回复
老的?
新的?
水晶版本?
minajo21 2003-03-10
  • 打赏
  • 举报
回复
或者谁有没有其它办法达到相同的效果?

多谢多谢了!
加载更多回复(12)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧