Accessing array elements: [ ] - subscript operator & VarSet()

Hi every one,

I write a loop function for 3 Array ( n =1 to 5) for all Candle bar (all element from i =0 to barcount).

I cannot use VarSet, because it will replace All element of this Array. The calculate is quite complicated to put in IIF.

So i have to write my own Element Set & Element Get myself.

Can you suggest a better way for my Element Set function?

Slist = "S0,S1,S2,S3,S4,S5";

function GetElement(textlist,n,i)
{
arraytemp = VarGet(StrExtract(textlist,n));
return arraytemp[i];
}

function SetElement(textlist,n,i, value)
{
switch( strExtract(textlist,n) )
{
	case "S1":
  	global S1;
        S1[i] = value;
        break;

	case "S2":
	global S2;
        S2[i] = value;
        break;
        
	case "S3":
	global S3;
        S3[i] = value;
		break;
	
        case "S4":
		global S4;
        S4[i] = value;
		break;

        case "S5":
		global S5;
        S5[i] = value;
		break;
}
}

It would be more helpful if you would post your looping code that calls SetElement and GetElement. It's likely those could be eliminated completely, but there's no way to tell without knowing how you're trying to use them.