| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1216 人关注过本帖
标题:又来求教了,有了点小问题
只看楼主 加入收藏
andyee
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2014-2-12
收藏
得分:0 
加了browse,else之后的语句是可以执行的,
是不是我不加browse,else就是个摆设?
2014-04-14 08:31
wangzhiyi
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:366
专家分:684
注 册:2014-4-9
收藏
得分:4 
楼主的代码本身没有问题,但是每次都是修改同样的那条记录,因为每次都是重新打开,再查找,再修改记录。不知道楼主这段代码想达到什么目的?
2014-04-14 08:35
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9819
专家分:27071
注 册:2012-2-5
收藏
得分:0 
REPLACE Record ? hamx.team WITH '非目标',hamx.rep WITH '非目标',hamx.regbj WITH 'XX',hamx.supbj WITH 'X',hamx.repbj WITH 'XXX'

坚守VFP最后的阵地
2014-04-14 08:35
andyee
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2014-2-12
收藏
得分:0 
以下是引用sdta在2014-4-14 08:35:04的发言:

REPLACE Record ? hamx.team WITH '非目标',hamx.rep WITH '非目标',hamx.regbj WITH 'XX',hamx.supbj WITH 'X',hamx.repbj WITH 'XXX'

版主,这个record ? 啥意思啊,显示语法错误
2014-04-14 08:49
andyee
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2014-2-12
收藏
得分:0 
SET TALK OFF
SET SAFETY OFF
CLOSE TABLES
axx=0
SELECT hatemp.month as months,pdtcode,spec,type1,type2,boxes,standn,SUM(qty) as sqty,SUM(pdtvalu) as spdtvalu FROM hatemp GROUP BY hatemp.month,hatemp.pdtcode,hatemp.spec,hatemp.type1,hatemp.type2,hatemp.boxes,hatemp.standn INTO CURSOR tag1
FOR tg=1 TO RECCOUNT()
   SELECT hatemp.month as months,pdtcode,spec,type1,type2,boxes,standn,SUM(qty) as sqty,SUM(pdtvalu) as spdtvalu FROM hatemp GROUP BY hatemp.month,hatemp.pdtcode,hatemp.spec,hatemp.type1,hatemp.type2,hatemp.boxes,hatemp.standn INTO CURSOR tag1
   GO tg
   tg1=months
   tg2=pdtcode
   tg3=spec
   tg4=standn
   tg5=type1
   tg6=type2
   tg7=boxes
   tg8=sqty
   tg9=spdtvalu
   ? RECNO()
   USE hamx
   APPEND BLANK
   REPLACE hamx.month WITH tg1,hamx.pdtcode WITH tg2,hamx.spec WITH tg3,hamx.type1 WITH tg5,hamx.type2 WITH tg6,hamx.boxes WITH tg7,hamx.qty WITH tg8,hamx.pdtvalu WITH tg9,hamx.standn WITH tg4
   IF USED('odrep') THEN
      SELECT odrep
   ELSE
      SELECT 0
      USE odrep
   ENDIF
   LOCATE FOR odrep.month-odrep.pdtcode-odrep.spec-odrep.standn==tg1-tg2-tg3-tg4
   ? FOUND()
   *BROWSE
   IF FOUND()
      REPLACE hamx.team WITH odrep.team,hamx.rep WITH odrep.rep,hamx.regbj WITH odrep.regbj,hamx.supbj WITH odrep.supbj,hamx.repbj WITH odrep.repbj,hamx.city WITH odrep.city,hamx.prov WITH odrep.prov
      *USE IN odrep
   ELSE
      axx=axx+1
      REPLACE hamx.team WITH '非目标',hamx.rep WITH '非目标',hamx.regbj WITH 'XX',hamx.supbj WITH 'X',hamx.repbj WITH 'XXX'
      *USE IN odrep

   ENDIF
   USE IN odrep
   USE IN hamx   
ENDFOR
?axx
CLOSE TABLES
RELEASE ALL
各位有空了帮忙看看,标红的字体是出问题的地方,使用browse之后,标红的语句可以执行,否则repl结果为空值。
我放了个axx在else之后测试了一下,axx是可以计数的。只是repl不正确。
2014-04-14 08:53
andyee
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2014-2-12
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册


用brow和不用brow的两次运行结果,请看图片
2014-04-14 08:54
zengjun81357
Rank: 2
等 级:论坛游民
帖 子:73
专家分:20
注 册:2011-3-27
收藏
得分:4 
以下是引用andyee在2014-4-14 08:23:00的发言:

 
H版,我locate for 表odrep
not found()情况下:  replace 表hamx with '非目标'  &&没有用到表odrep的东西啊?
这也会受影响吗?

hu9jj班长说得对,repl 替换需要指明记录的,你加个条件  FOR odrep.month-odrep.pdtcode-odrep.spec-odrep.standn<>tg1-tg2-tg3-tg4
2014-04-14 08:56
andyee
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2014-2-12
收藏
得分:0 
以下是引用wangzhiyi在2014-4-14 08:35:03的发言:

楼主的代码本身没有问题,但是每次都是修改同样的那条记录,因为每次都是重新打开,再查找,再修改记录。不知道楼主这段代码想达到什么目的?

tg1 tg2 tg3 tg4 的内容在变化的
2014-04-14 09:08
andyee
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2014-2-12
收藏
得分:0 
以下是引用zengjun81357在2014-4-14 08:56:42的发言:


hu9jj班长说得对,repl 替换需要指明记录的,你加个条件  FOR odrep.month-odrep.pdtcode-odrep.spec-odrep.standn<>tg1-tg2-tg3-tg4

thank you
搞定了,很感谢

 IF USED('odrep') THEN
      SELECT odrep
   ELSE
      SELECT 0
      USE odrep
   ENDIF
   LOCATE FOR odrep.month-odrep.pdtcode-odrep.spec-odrep.standn==tg1-tg2-tg3-tg4
   IF FOUND()
      axx=axx+1
      REPLACE hamx.team WITH odrep.team,hamx.rep WITH odrep.rep,hamx.regbj WITH odrep.regbj,hamx.supbj WITH odrep.supbj,hamx.repbj WITH odrep.repbj,hamx.city WITH odrep.city,hamx.prov WITH odrep.prov
   ELSE
      LOCATE FOR odrep.month-odrep.pdtcode-odrep.spec-odrep.standn<>tg1-tg2-tg3-tg4
      IF FOUND()
         bxx=bxx+1
         REPLACE hamx.team WITH '非目标',hamx.rep WITH '非目标',hamx.regbj WITH 'XX',hamx.supbj WITH 'X',hamx.repbj WITH 'XXX'

      ENDIF
   ENDIF
   USE IN odrep
   USE IN hamx

修改之后正确执行,这个问题我已经记在葵花宝典上了,以后遇到同样的情况就不会出错了
2014-04-14 09:23
liuxingang28
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:山东济南
等 级:贵宾
威 望:47
帖 子:652
专家分:2160
注 册:2014-2-7
收藏
得分:4 
楼主的真正错误是对 Replace 语句的错误使用。我曾在 Taifu945版主发表的《Foxpro 入门手册》的回帖中专门论述过。
因为当前工作区是 odrep,楼主试图通过在字段前加表别名的方式,去更新另一表的字段,如:Replace hamx.team with odrep.team,这种方式非常危险,因为它有 2 个先决条件:第一个是当前工作区必须有表打开,否则会报错;第二个是当前工作区的指针不能是表尾,即EOF()=.t.,否则虽然不报错,但不会执行任何替换操作。因此,千万不能采用这种方式。
正确的代码有2种写法:
第一种:
select hamx
replace team with odrep.team
第二种:
replace team with odrep.team in hamx

泉城飞狐
2014-04-14 10:17
快速回复:又来求教了,有了点小问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014248 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved