osdak 發表於 14-11-28 19:31

在loop中修改str

大大,

想請教, 如果我有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.




joshsmi 發表於 14-11-29 04:02

本帖最後由 joshsmi 於 14-11-29 04:05 編輯

See dynamic variables


for( i = 1; i < 6; i++ )
{
    VarSet( "HHV" + i, HHV(O, i ) );
}


Then either use VarGet to call them back


for( i = 1; i < 6; i++ )
{
    Plot( VarGet( "HHV" + i ), "HHV" + i, colorRed, styleline );
}


or picking single variable i.e


Plot( HHV1, "HHV1", colorRed, styleline );


etc.


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

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


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


for( i = 1; i < 6; i++ )
{
    Plot( VarGet( "HHV" + i ), "HHV" + i, colorRed, styleline );
}

osdak 發表於 14-11-29 12:11

joshsmi 發表於 14-11-29 04:02 static/image/common/back.gif
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 + "");


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


thanks!

saucer 發表於 14-11-29 13:01

osdak 發表於 14-11-29 12:11 static/image/common/back.gif
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 ;


osdak 發表於 14-11-29 14:28

saucer 發表於 14-11-29 13:01 static/image/common/back.gif
除非 AB有提供其他便捷方式

不然就是倒出來再取


是, 謝謝. 我剛剛也是用這方法. 只是想看看有沒有更快的^_^

joshsmi 發表於 14-11-29 23:46

本帖最後由 joshsmi 於 14-11-29 23:48 編輯

If you just pick on variable then simply use

no7element = HHV5;

no need for varget

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


for ( x = 1; x <= xmax; x++ )
{
      var = VarGet( tablename + x );
      //
      for ( i = 0; i < BarCount; i++ )
          {
            if( var ....
         ....

or whatever
頁: [1]
查看完整版本: 在loop中修改str