在VFP6.0中为何类似if substr(fxdate,5,1) = '-'的条件总不成立?

xylegend 2005-06-04 05:46:05
在VFP6.0中为何类似if substr(fxdate,5,1) = '-'的条件总不成立?
具体如下:
if substr(fxdate,5,1) = '-'
replace month3 with substr(fxdate,4,1) all
replace day3 with substr(fxdate,6,2) all
else
replace month3 with substr(fxdate,4,2) all
replace day3 with substr(fxdate,7,2) all
endif
其中fxdate字段的值为05-3-8,字段类型为char,但是if substr(fxdate,5,1) = '-'条件总为假
好困惑。。。(个人经验:凡是涉及判断字符相等的时候总为假)
明明执行?substr(fxdate,5,1)时得到的字符就是'-'啊!!!
请教各位大侠,谢谢!
...全文
138 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
xylegend 2005-06-05
  • 打赏
  • 举报
回复
我用命令执行?substr(fxdate,5,1)的结果就是字符'-'啊!!!!!
是不是让人莫名其妙呢。。。。
xylegend 2005-06-05
  • 打赏
  • 举报
回复
如果fxdate字段是日期型那么我的这个判断早就出错了:if substr(fxdate,5,1) = '-'
xylegend 2005-06-05
  • 打赏
  • 举报
回复
fxdate字段是字符型啊,就是因为是字符型啊。搞得人莫名其妙
本来数据是xsl的,转成txt最后才导入VFP表里边的啊。
如果fxdate字段是日期型,那么文本数据是不能导入的啊(至少会提示类型不匹配的吧?)
LuckyNT 2005-06-05
  • 打赏
  • 举报
回复
你用了all```所以不是把所有数据都处理成
else
replace month3 with substr(fxdate,4,2) all
replace day3 with substr(fxdate,7,2) all
endif
就是处理成
replace month3 with substr(fxdate,4,1) all
replace day3 with substr(fxdate,6,2) all
else
---------
晕.....如果要替换这个表的字段你还需要用一个循环了控制指针的移动````
LuckyNT 2005-06-05
  • 打赏
  • 举报
回复
if substr(fxdate,5,1) = '-'
replace month3 with substr(fxdate,4,1) all
replace day3 with substr(fxdate,6,2) all
else
replace month3 with substr(fxdate,4,2) all
replace day3 with substr(fxdate,7,2) all
endif
你为什么要加范围all?晕```
if substr(alltrim(fxdate),5,1) ='-'
replace month3 with substr(fxdate,4,1)
replace day3 with substr(fxdate,6,2)
else
replace month3 with substr(fxdate,4,2)
replace day3 with substr(fxdate,7,2)
endif
xylegend 2005-06-05
  • 打赏
  • 举报
回复
唉,郁闷。老是将字段名打错,以上所出现的fxdate,txdate等字段指的均是同一字段
字段名称任由各位喜欢自己改吧
xuancaoer 2005-06-05
  • 打赏
  • 举报
回复
楼上的你说对了,原来是没有all的,搞烦了改的
是循环指针的问题
xylegend 2005-06-05
  • 打赏
  • 举报
回复
用以测试的数据(txdate字段)可以是:
05-3-8
05-2-7
05-4-10
05-03-08
05-12-8
05-10-17
xylegend 2005-06-05
  • 打赏
  • 举报
回复
呵,不好意思。现在我的表和程序都在公司。。。
不过热心的大侠可以这样测试:

一、建一个这样的表(3个字段分别为如下,且均为char型,长度10)
txdate month3 day3

二、将txdate字段复制插入05-3-8,若干行

三、将如下程序片断另存为test.prg,然后执行即可见结果
if substr(fxdate,5,1) = '-'
replace month3 with substr(fxdate,4,1) all
replace day3 with substr(fxdate,6,2) all
else
replace month3 with substr(fxdate,4,2) all
replace day3 with substr(fxdate,7,2) all
endif

LuckyNT 2005-06-05
  • 打赏
  • 举报
回复
呵呵``怪了```
如果方便的话把你的表传给我一份```iluckynt@hotmail.com
我也想知道到底为什么出现这个情况``呵呵``
xylegend 2005-06-05
  • 打赏
  • 举报
回复
to楼上的朋友:
无论是if substr(sxdate,5,1) ='-'
或者if substr(txdate,5,1) =='-'
还是if alltrim(substr(txdate,5,1)) =='-'
再或者是flag=substr(txdate,5,1) == '-'
条件值均为假
--------------------------------------------------
我早已说过了。。。
况且用命令执行?substr(fxdate,5,1)的结果就是字符'-'
LuckyNT 2005-06-05
  • 打赏
  • 举报
回复
substr(fxdate,5,1)
取出来的时候把首尾空格取走
substr(alltrim(fxdate),5,1)
试试吧```
guywei 2005-06-04
  • 打赏
  • 举报
回复
同意,用substr(dtoc(txdate),5,1)
dfwxj 2005-06-04
  • 打赏
  • 举报
回复
问题所在:fxdate是日期型,对吧?

改成字符型
xylegend 2005-06-04
  • 打赏
  • 举报
回复
无论是if substr(sxdate,5,1) ='-'
或者if substr(txdate,5,1) =='-'
还是if alltrim(substr(txdate,5,1)) =='-'
再或者是flag=substr(txdate,5,1) == '-'
条件值均为假

2,722

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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