标题:如何提高程序运行速度
只看楼主
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用fdqzy在2020-9-16 14:34:51的发言:

再请教关于行统计的问题:
我的常规处理办法是
create cursor b1 (c1 N(3),c2 N(3),m c(3))
insert into b1 values (70,54,"")
insert into b1 values (58,54,"")
insert into b1 values (49,86,"")
insert into b1 values (66,86,"")
insert into b1 values (75,96,"")

FOR i=1 TO RECCOUNT()
GO i
kk=''
IF c1>=60
kk=kk+'1'
ENDIF
IF c1<60
kk=kk+'0'
ENDIF
IF c2>=60
kk=kk+'1'
ENDIF
IF c2<60
kk=kk+'0'
ENDIF
GO i
REPLACE m WITH ALLTRIM(kk)
endfor

求简捷的处理方法!

一句
REPLACE ALL m WITH IIF(c1<60,"0","1") + IIF(c2<60,"0","1")
2020-09-16 16:24
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用sdta在2020-9-16 15:09:24的发言:

create cursor b1 (m1 c(2),m2 c(2),m3 c(2),m4 c(2),m5 c(2),p1 c(3),p2 c(3),p3 c(3))
insert into b1 values ("M1","","M3","M4","","","","")
insert into b1 values ("M1","","","M4","","","","")
insert into b1 values ("","M2","M3","M4","M5","","","")
insert into b1 values ("","","","M4","","","","")
insert into b1 values ("","","M3","M4","M5","","","")
SCAN
    n1 = OCCURS("M", m1 + m2 + m3 + m4 + m5)
    n1 = IIF(n1 > 3, 3, n1)
    REPLACE ("P" + TRANSFORM(n1)) WITH "P" + TRANSFORM(n1)
ENDSCAN
BROWSE

谢谢了!
2020-09-16 16:37
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用sdta在2020-9-16 15:18:57的发言:

我一直坚持先学后用,不是现学现用,原因大家可以自己去想像

应该是这样,我现在发的帖子,是以前学6.0时的代码,且是目前因工作需要解决不了,故求助,也学到了不少知识,以后要多学。
2020-09-16 16:43
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用吹水佬在2020-9-16 16:24:38的发言:


一句
REPLACE ALL m WITH IIF(c1<60,"0","1") + IIF(c2<60,"0","1")

回避FOR,快多了,谢谢!
2020-09-16 16:45
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用fdqzy在2020-9-16 14:34:51的发言:

统计:
create cursor b1 (m1 c(2),m2 c(2),m3 c(2),m4 c(2),m5 c(2),p1 c(3),p2 c(3),p3 c(3))
insert into b1 values ("M1","","M3","M4","","","","")
insert into b1 values ("M1","","","M4","","","","")
insert into b1 values ("","M2","M3","M4","M5","","","")
insert into b1 values ("","","","M4","","","","")
insert into b1 values ("","","M3","M4","M5","","","")

FOR i=1 TO RECCOUNT()
GO i
kk=0
IF 'M'$m1
kk=kk+1
ENDIF
IF 'M'$m2
kk=kk+1
ENDIF
IF 'M'$m3
kk=kk+1
ENDIF
IF 'M'$m4
kk=kk+1
ENDIF
IF 'M'$m5
kk=kk+1
ENDIF
GO i
REPLACE p1 WITH 'P1' FOR kk=1 AND RECNO()=i
REPLACE p2 WITH 'P2' FOR kk=2 AND RECNO()=i
REPLACE p3 WITH 'P3' FOR kk>2 AND RECNO()=i

endfor

求简捷的处理方法!

近来比较强调“内循环”
kk=0
REPLACE ALL ;
    p1 WITH IIF(fun()=1, 'P1', ''),;
    p2 WITH IIF(kk=2, 'P2', ''),;
    p3 WITH IIF(kk>2, 'P3', '')
SELECT * FROM b1
RETURN

FUNCTION fun()
    kk = OCCURS("M",m1+m2+m3+m4+m5)
    RETURN kk
ENDFUNC
2020-09-16 16:51
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:0 
编程三步曲
一:思路
二:方法
三:代码优化

坚守VFP最后的阵地
2020-09-16 17:01
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用吹水佬在2020-9-16 16:51:52的发言:


近来比较强调“内循环”
kk=0
REPLACE ALL ;
    p1 WITH IIF(fun()=1, 'P1', ''),;
    p2 WITH IIF(kk=2, 'P2', ''),;
    p3 WITH IIF(kk>2, 'P3', '')
SELECT * FROM b1
RETURN

FUNCTION fun()
    kk = OCCURS("M",m1+m2+m3+m4+m5)
    RETURN kk
ENDFUNC

在老师的指导下,我仿照如下:
程序代码:
create cursor b1 (m1 c(2),m2 c(2),m3 c(2),m4 c(2),m5 c(2),p1 c(3),p2 c(3),p3 c(3))
insert into b1 values ("M1","","M3","M4","","","","")
insert into b1 values ("M1","","","M4","","","","")
insert into b1 values ("","M2","M3","M4","M5","","","")
insert into b1 values ("","","","M4","","","","")
insert into b1 values ("","","M3","M4","M5","","","")

REPLACE ALL ;
            p1 WITH IIF(OCCURS("M", m1 + m2 + m3 + m4 + m5)=1 ,"P1", "");
            p2 WITH IIF(OCCURS("M", m1 + m2 + m3 + m4 + m5)=2 ,"P2", "");
            p3 WITH IIF(OCCURS("M", m1 + m2 + m3 + m4 + m5)>2 ,"P3", "")

可以否?
2020-09-16 17:30
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用sdta在2020-9-16 17:01:47的发言:

编程三步曲
一:思路
二:方法
三:代码优化

谢谢!这是我应该努力的方向。
2020-09-16 17:33
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
回复 57楼 fdqzy
可以,但用OCCURS重复做同一件事有点浪费时间。
2020-09-16 18:01
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
通过近几天老师的指教,基本上找到了我原代码运行效率不高的原因,以及解决问题的思路,给工作中解决实际问题带来了极大的方便。
谢谢各位老师!请今后多指教。
2020-09-16 18:03



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




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

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