版主大大求助,这个For循环有点问题。

fojiao8745 2017-12-07 03:04:49
RT,如下图,为什么这个For循环会跳出,a的值并没有达到目标值啊。

下面是代码:
lcarea = '昆山——南京'
lctime = '17/12/30'
lccontent = '有票啦'
oxhttp=CREATEOBJECT("InternetExplorer.Application")
oxhttp.NAVIGATE('https://train.qunar.com/stationToStation.htm?fromStation=%E6%98%86%E5%B1%B1%E5%8D%97&toStation=%E5%8D%97%E4%BA%AC&date=2017-12-30')
oxhttp.VISIBLE = .F.
DO WHILE oxhttp.ReadyState != 4
INKEY(1,'H')
ENDDO
lnamount = 0
lcString = oxhttp.DOCUMENT.body.innerhtml
oxhttp.QUIT
RELEASE oxhttp
FOR a = 1 TO LEN(lcString)
IF SUBSTR(lcString,a,14) == '列车运行图调整'
lnamount = lnamount + 1
ENDIF

IF lnamount > 20 AND a = (LEN(lcString) - 1)
MESSAGEBOX("现在的列车调整数量为"+ALLTRIM(STR(lnamount)),48,'Tips',500)
oxhttp=CREATEOBJECT("InternetExplorer.Application")
oxhttp.NAVIGATE('https://train.qunar.com/stationToStation.htm?fromStation=%E6%98%86%E5%B1%B1%E5%8D%97&toStation=%E5%8D%97%E4%BA%AC&date=2017-12-30')
oxhttp.VISIBLE = .F.
DO WHILE oxhttp.ReadyState != 4
INKEY(1,'H')
ENDDO
a = 1
lnamount = 0
lcString = oxhttp.DOCUMENT.body.innerhtml
oxhttp.QUIT
RELEASE oxhttp
ENDIF
ENDFOR
...全文
548 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xclzteb 2018-04-09
  • 打赏
  • 举报
回复
写循环代码的时候尽量不要去修改变量的值,容易引起混乱。
fojiao8745 2017-12-11
  • 打赏
  • 举报
回复
引用 3 楼 dkfdtf 的回复:
有可能吧,你看到的循环结束时的 LEN(lcString) 值已不是最初的值,因为循环中 lcString = oxhttp.DOCUMENT.body.innerhtml 改变了 lcString 的值 而 vfp 对 for 循环的 start 和 end 值处理是仅在循环开始时取一次,中间改变 end 值是不会影响循环次数的 例如: lnEnd = 100 for a = 1 to lnEnd ... lnEnd = 500 ... endfor ? a 则只会循环 100 次,而不会是 500 次,也就是说,最后 ? a 显示的是 101 而不是 501 注意下 vfp 的文档: The values of nInitialValue, nFinalValue, and nIncrement are read only initially. However, changing the value of the counter VarName inside the loop affects the number of times the loop is executed. Changing the value of nFinalValue in a FOR loop has no effect.
6666理解了,版主大大牛逼
fojiao8745 2017-12-11
  • 打赏
  • 举报
回复
引用 1 楼 gxbsdzf 的回复:
上述代码在我这试运行没出错啊。我这调用的是IE8。
你让他多跑一会,然后在ENDFOR后面加中断,然后等他中断了,你去看一下FOR循环a的值
都市夜猫 2017-12-11
  • 打赏
  • 举报
回复
有可能吧,你看到的循环结束时的 LEN(lcString) 值已不是最初的值,因为循环中 lcString = oxhttp.DOCUMENT.body.innerhtml 改变了 lcString 的值
而 vfp 对 for 循环的 start 和 end 值处理是仅在循环开始时取一次,中间改变 end 值是不会影响循环次数的
例如:
lnEnd = 100
for a = 1 to lnEnd
...
lnEnd = 500
...
endfor
? a
则只会循环 100 次,而不会是 500 次,也就是说,最后 ? a 显示的是 101 而不是 501

注意下 vfp 的文档:
The values of nInitialValue, nFinalValue, and nIncrement are read only initially. However, changing the value of the counter VarName inside the loop affects the number of times the loop is executed. Changing the value of nFinalValue in a FOR loop has no effect.
gxbsdzf 2017-12-10
  • 打赏
  • 举报
回复
上述代码在我这试运行没出错啊。我这调用的是IE8。

2,748

社区成员

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

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