注册 登录
编程论坛 VFP论坛

求助:代码优化

qjszkb 发布于 2022-03-28 11:04, 1329 次点击
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
只有本站会员才能查看附件,请 登录
6 回复
#2
吹水佬2022-03-28 11:14
先详细说清楚在做什么,想要什么结果
#3
qjszkb2022-03-28 11:22
处理前和处理后,非常感谢。
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
#4
sdta2022-03-28 12:04
程序代码:
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
#5
wengjl2022-03-28 12:39
程序代码:
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
#6
mywisdom882022-03-28 13:43
回复 楼主 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
#7
qjszkb2022-03-28 14:28
谢谢各位帮助
1