COCO研究院

 找回密碼
 註冊
搜索
查看: 2093|回復: 5

在loop中修改str

[複製鏈接]
發表於 14-11-28 19:31 | 顯示全部樓層 |閱讀模式
大大,

想請教, 如果我有5個array, 比如:

HHV1 = HHV(Open, 1);
HHV2 = HHV(Open, 2);
HHV3 = HHV(Open, 3);
HHV4 = HHV(Open, 4);
HHV5 = HHV(Open, 5);

但如果我不想寫5行AFL, 我想用loop自動幫ARRAY命名, 和幫他定義, 比如:

for( i = 1; i < 5; i++ )
{
HHV+"i" = HHV(Open, "i");
}


我知道上面的loop是錯誤, 但我只想帶出我的意思, 請問應該如何改為正確?

thanks.




發表於 14-11-29 04:02 | 顯示全部樓層
本帖最後由 joshsmi 於 14-11-29 04:05 編輯

See dynamic variables


  1. for( i = 1; i < 6; i++ )
  2. {
  3.     VarSet( "HHV" + i, HHV(O, i ) );
  4. }
複製代碼


Then either use VarGet to call them back


  1. for( i = 1; i < 6; i++ )
  2. {
  3.     Plot( VarGet( "HHV" + i ), "HHV" + i, colorRed, styleline );
  4. }
複製代碼


or picking single variable i.e


  1. Plot( HHV1, "HHV1", colorRed, styleline );
複製代碼


etc.


On the other and if you already have a ready list of variables like

  1. HHV1 = HHV(Open, 1);
  2. HHV2 = HHV(Open, 2);
  3. HHV3 = HHV(Open, 3);
  4. HHV4 = HHV(Open, 4);
  5. HHV5 = HHV(Open, 5);
複製代碼


then you can also call those ones via VarGet, i.e.


  1. for( i = 1; i < 6; i++ )
  2. {
  3.     Plot( VarGet( "HHV" + i ), "HHV" + i, colorRed, styleline );
  4. }
複製代碼

評分

參與人數 2金錢 +7 收起 理由
kilroy + 5 Great!
lwhuang + 2 這功能我想要好久,原來這樣用.

查看全部評分

 樓主| 發表於 14-11-29 12:11 | 顯示全部樓層
joshsmi 發表於 14-11-29 04:02
See dynamic variables

Thanks Joshsmi.

One more question, if i wanna pick one of the elements from the array, by using VarGet, how can I do that? I tried:




HHV5 = HHV(Open, 5);


no7element = VarGet("HHV" + 5 + "[7]");


I wanted to pick the 7th element from the array HHV5, but it's failed.


thanks!
發表於 14-11-29 13:01 | 顯示全部樓層
osdak 發表於 14-11-29 12:11
Thanks Joshsmi.

One more question, if i wanna pick one of the elements from the array, by using V ...

除非 AB有提供其他便捷方式

不然就是倒出來再取

buf = VarGet("HHV" + 5);

no7element = buf[7] ;


 樓主| 發表於 14-11-29 14:28 | 顯示全部樓層
saucer 發表於 14-11-29 13:01
除非 AB有提供其他便捷方式

不然就是倒出來再取

是, 謝謝. 我剛剛也是用這方法. 只是想看看有沒有更快的^_^
發表於 14-11-29 23:46 | 顯示全部樓層
本帖最後由 joshsmi 於 14-11-29 23:48 編輯

If you just pick on variable then simply use

no7element = HHV5[7];

no need for varget

Otherwise if it is all variables and you need to loop barcount then I would do it this way.


  1. for ( x = 1; x <= xmax; x++ )
  2. {  
  3.         var = VarGet( tablename + x );
  4.         //
  5.         for ( i = 0; i < BarCount; i++ )
  6.           {
  7.             if( var[i] ....
  8.          ....

複製代碼
or whatever
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-12-23 05:17

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |