奇狐社區論壇
在這個頁面顯示本主題全部的 2 個文章

奇狐社區論壇 (http://www.chiefox.com.tw/bbs/index.php)
- 問題交流 (http://www.chiefox.com.tw/bbs/forumdisplay.php?forumid=28)
-- [求救]換成5.2, 公式出現BUG- 指標越界或超出有效區間 (http://www.chiefox.com.tw/bbs/showthread.php?threadid=22616)


由 亞當理論 在 2020-09-05 22:26 發表:

[求救]換成5.2, 公式出現BUG- 指標越界或超出有效區間

Any one could help:

cc:=CLOSE;
oo:=OPEN;
hh:=HIGH;
ll:=LOW;
top:=HIGH;
bot:=LOW;
xx[1]:=1;
kk:=1;
for i=1 to DATACOUNT do begin IF xx[i]=1 then begin top[i]:=hh[i];
end;
IF xx[i-1]=1 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
xx[i]:=2;
end;
end;
IF xx[i-1]=2 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
bot[i]:=ll[i];
xx[i]:=3;
end;
end;
IF xx[i-1]=3 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=4;
end;
end;
IF xx[i-1]=4 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=5;
end;
end;
IF xx[i-1]=5 then begin IF ll[i]<bot[i-1] or hh[i]>top[i-1] then begin top[i]:=hh[i];
bot[i]:=hh[i];
xx[i]:=1;
end;
else begin bot[i]:=bot[i-1];
top[i]:=top[i-1];
xx[i]:=5;
end;
end;
end;
for j=1 to DATACOUNT do begin IF xx[j]=5 and xx[j-1]=4 then begin for k=j-1 downto j-kk do begin top[k]:=top[j];
bot[k]:=bot[j];
end;
end;
IF xx[j-1]=5 and xx[j]=1 then kk:=0;
kk:=kk+1;
end;


由 cgjj 在 2020-09-05 23:39 發表:

回覆: [求救]換成5.2, 公式出現BUG- 指標越界或超出有效區間

引用:
最初由 亞當理論 發表
Any one could help:

cc:=CLOSE;
oo:=OPEN;
hh:=HIGH;
ll:=LOW;
top:=HIGH;
bot:=LOW;
xx[1]:=1;
kk:=1;
for i=1 to DATACOUNT do begin IF xx[i]=1 then begin top[i]:=hh[i];
end;
IF xx[i-1]=1 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
xx[i]:=2;
end;
end;
IF xx[i-1]=2 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
bot[i]:=ll[i];
xx[i]:=3;
end;
end;
IF xx[i-1]=3 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=4;
end;
end;
IF xx[i-1]=4 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=5;
end;
end;
IF xx[i-1]=5 then begin IF ll[i]<bot[i-1] or hh[i]>top[i-1] then begin top[i]:=hh[i];
bot[i]:=hh[i];
xx[i]:=1;
end;
else begin bot[i]:=bot[i-1];
top[i]:=top[i-1];
xx[i]:=5;
end;
end;
end;
for j=1 to DATACOUNT do begin IF xx[j]=5 and xx[j-1]=4 then begin for k=j-1 downto j-kk do begin top[k]:=top[j];
bot[k]:=bot[j];
end;
end;
IF xx[j-1]=5 and xx[j]=1 then kk:=0;
kk:=kk+1;
end;



公式本身就撰寫有誤,奇狐 v5.2 只是檢查的比較嚴格而已,防止越界!

奇狐的數列是自1數起,不是從零數起
故不存在第零個元素,也就是不存在 n[0]

你的兩個迴圈 i 和 j ,都是自1開始遞增
當 i-1 或 j-1 時,會發生 1-1=0 的情況
故會被警告越界!!!
改從2開始遞增就可解決問題


全部時間均為台灣時間, 現在時間為16:24
在這個頁面顯示本主題全部的 2 個文章


Powered by: vBulletin Version 2.3.0 - Copyright©2000-, Jelsoft Enterprises Limited.

簡愛洋行 製作 Copyright 2003-. All Rights Reserved.