标题:求助:代码优化
只看楼主
qjszkb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2022-3-28
结帖率:100%
已结贴  问题点数:20 回复次数:6 
求助:代码优化
SCAN
   FOR i=1 TO 8
     IF a4=" " AND a5<>" "
        REPLACE a4 WITH a5
     ENDIF
     IF a4=a5
        REPLACE a5 WITH " "
     ENDIF   
     IF a3=" " AND a4<>" "
        REPLACE a3 WITH a4
     ENDIF
     IF a3=a4
        REPLACE a4 WITH " "
     ENDIF
     IF a2=" " AND a3<>" "
        REPLACE a2 WITH a3
     ENDIF
     IF a2=a3
        REPLACE a3 WITH " "
     ENDIF
     IF a1=" " AND a2<>" "
        REPLACE a1 WITH a2
     ENDIF
     IF a1=a2
        REPLACE a2 WITH " "
     ENDIF
   ENDFOR
ENDSCAN
aaa.rar (1.62 KB)
搜索更多相关主题的帖子: REPLACE IF WITH 优化 AND 
2022-03-28 11:04
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:5 
先详细说清楚在做什么,想要什么结果
2022-03-28 11:14
qjszkb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2022-3-28
得分:0 
处理前和处理后,非常感谢。
2022-03-28 11:22
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:5 
程序代码:
CLOSE DATABASES 
SELECT * FROM dbf1 WHERE .f. INTO CURSOR dbf2 READWRITE 
SELECT dbf1
SCAN 
    lcStr = ""
    FOR ln = 1 TO FCOUNT()
        IF NOT EVALUATE(FIELD(ln)) $ lcStr
            lcStr = lcStr + "," + EVALUATE(FIELD(ln))
        ENDIF 
    ENDFOR
    ALINES(la, lcStr, 5, ",")
    DIMENSION la[1, ALEN(la, 1)]
    INSERT INTO dbf2 FROM ARRAY la
ENDSCAN 
SELECT dbf2
BROWSE 

坚守VFP最后的阵地
2022-03-28 12:04
wengjl
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:108
帖 子:2175
专家分:3785
注 册:2007-4-27
得分:5 
程序代码:
CLOSE DATABASES 
SELECT 0
USE dbf1 ALIAS kg
fou=.t.
SCAN
    DO WHILE fou=.t.
      fou=.f.
      IF a4=" " AND a5<>" "
         REPLACE a4 WITH a5
         fou=.t.         
      ENDIF
      IF a4=a5 AND !EMPTY(a4)
         REPLACE a5 WITH " "
         fou=.t.         
      ENDIF    
      IF a3=" " AND a4<>" "
         REPLACE a3 WITH a4
         fou=.t.         
      ENDIF
      IF a3=a4 AND !EMPTY(a3)
         REPLACE a4 WITH " "
         fou=.t.         
      ENDIF
      IF a2=" " AND a3<>" "
         REPLACE a2 WITH a3
         fou=.t.         
      ENDIF
      IF a2=a3 AND !EMPTY(a2)
         REPLACE a3 WITH " "
         fou=.t.         
      ENDIF
      IF a1=" " AND a2<>" "
         REPLACE a1 WITH a2
         fou=.t.         
      ENDIF
      IF a1=a2 AND !EMPTY(a1)
         REPLACE a2 WITH " " 
         fou=.t.         
      ENDIF
    ENDDO 
    
    SELECT kg
    fou=.t.

 ENDSCAN

只求每天有一丁点儿的进步就可以了
2022-03-28 12:39
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:5 
回复 楼主 qjszkb
USE C:\aaa\dbf1 IN 0
SELECT * FROM dbf1 INTO CURSOR dbf2 READWRITE
update dbf2 set a1=iif(!EMPTY(a2),a2,iif(!EMPTY(a3),a3,iif(!EMPTY(a4),a4,a5))) where empty(a1)
update dbf2 set a2=iif(!EMPTY(a3) and !ALLTRIM(a3)==ALLTRIM(a1),a3,iif(!EMPTY(a4) and !ALLTRIM(a4)==ALLTRIM(a1),a4,a5))
update dbf2 set a3=iif(!EMPTY(a4) and !ALLTRIM(a4)==ALLTRIM(a2),a4,IIF(!EMPTY(a5) AND !ALLTRIM(a5)==ALLTRIM(a2),a5,""))
update dbf2 set a4=iif(!EMPTY(a5) and !ALLTRIM(a5)==ALLTRIM(a3) AND !ALLTRIM(a5)==ALLTRIM(a2),a5,"")
update dbf2 set a5=iif(ALLTRIM(a5)==ALLTRIM(a4),"",IIF(ALLTRIM(a5)==ALLTRIM(a3),"",IIF(ALLTRIM(a5)==ALLTRIM(a2),"",IIF(ALLTRIM(a5)==ALLTRIM(a1),"",a5))))
brow
2022-03-28 13:43
qjszkb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2022-3-28
得分:0 
谢谢各位帮助
2022-03-28 14:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-508687-1-1.html




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

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