标题:帮忙优化代码
只看楼主
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
结帖率:76.81%
已结贴  问题点数:20 回复次数:2 
帮忙优化代码
对表中每个字段连续出现的值,依次斌顺序值:
程序代码:
create cursor b1 (jnh N(2),m1 c(3),m2 c(3),m3 c(3))
insert into b1 values (1,"M1","","M3")
insert into b1 values (2,"","M2","")
insert into b1 values (3,"M1","","M3")
insert into b1 values (4,"","M2","")
insert into b1 values (5,"M1","","M3")
insert into b1 values (6,"M1","","M3")
insert into b1 values (7,"M1","","")
insert into b1 values (8,"","M2","")
insert into b1 values (9,"M1","","M3")
insert into b1 values (10,"M1","","M3")
insert into b1 values (11,"M1","","M3")
insert into b1 values (12,"M1","","M3")
insert into b1 values (13,"M1","","")
insert into b1 values (14,"","M2","")


dxcount=Afields(dxarray)
For j=2 To dxcount

    Select b1
    Select jnh,&dxarray(j,1) From b1 Where Not !Empty(&dxarray(j,1)) Into Cursor ls
    nxs=Reccount()
    If nxs>0
        Dimension qs(nxs)
    Else
        Select ls
        Use
        Loop
    Endif
    For p=1 To nxs  &&存储某类qsz段
        Go p
        Store jnh To qs(p)
    Endfor
    Select ls
    Use

    Select b1
    Calculate Max(qs(nxs)) To qsmax
    For mm=1 To nxs
        If mm=1
            Set Filter To jnh<qs(mm) And !Empty(&dxarray(j,1))
        Endif
        If mm<>1

            Set Filter To jnh>qs(mm-1) And jnh<=qs(mm) And !Empty(&dxarray(j,1))

        Endif
        Count To jns
        Go top
For kk=1 To jns
        Replace &dxarray(j,1) With Alltrim(Str(kk)) 
Skip 
Endfor
    Endfor
    Set Filter To jnh>qsmax And !Empty(&dxarray(j,1))
    Count To jns

    Go top
For kk=1 To jns
    Replace &dxarray(j,1) With Alltrim(Str(kk))
Skip 
Endfor
Endfor
Select b1
Set Filter To

Brow

这段代码循环太多,对多字段、多记录运行太慢,能否优化一下,谢谢!
搜索更多相关主题的帖子: Select For values into insert 
2020-10-31 19:55
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:20 
程序代码:
create cursor b1 (jnh N(2),m1 c(3),m2 c(3),m3 c(3))
insert into b1 values (1,"M1","","M3")
insert into b1 values (2,"","M2","")
insert into b1 values (3,"M1","","M3")
insert into b1 values (4,"","M2","")
insert into b1 values (5,"M1","","M3")
insert into b1 values (6,"M1","","M3")
insert into b1 values (7,"M1","","")
insert into b1 values (8,"","M2","")
insert into b1 values (9,"M1","","M3")
insert into b1 values (10,"M1","","M3")
insert into b1 values (11,"M1","","M3")
insert into b1 values (12,"M1","","M3")
insert into b1 values (13,"M1","","")
insert into b1 values (14,"","M2","")
SELECT * FROM b1 INTO CURSOR b2 READWRITE 

FOR lnj = 2 TO FCOUNT()
    n1 = 0
    SCAN 
        c1 = EVALUATE(FIELD(lnj))        
        IF EMPTY(c1)
            n1 = 0
            REPLACE (FIELD(lnj)) WITH ""
        ELSE 
            n1 = n1 + 1
            REPLACE (FIELD(lnj)) WITH TRANSFORM(n1)
        ENDIF
    ENDSCAN
ENDFOR
BROWSE 

坚守VFP最后的阵地
2020-10-31 21:01
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
回复 2楼 sdta
谢谢,比以前快多了!
2020-10-31 21:38



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




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

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