Forum Discussion

Acckiy's avatar
12 years ago

How to pass the MainMenu[id] value through an array?


Hi!

I need automatically make tree of MainMenu, using ID of menu items.

====


function FindMenu()

{
var arr = new Array();

var MainMenu = Sys["Process"]("myprocess")["VCLObject"]("fmMain")["MainMenu"];



//Makes list of all MainMenu items id.


  for (var i = 0; i < Count; i++)

      

      {

        var Item = MainMenu["Items"](i);

        arr = Item["id"];

        Log.Message("" + arr, "");

      }




//Makes list of all MainMenu SubMenu items 


  for (var i = 0; i < Count; i++)

      {

        var id = arr;

        var SubMenuCnt = MainMenu["Items"](id)["SubMenu"]["Count"];

        Log.Message("" +SubMenuCnt, "");

      }

}
===

error "Object needed" appears at this string:

var SubMenuCnt = MainMenu["Items"](id)["SubMenu"]["Count"];



I know that this string work fine:

var SubMenuCnt = MainMenu["Items"]("[1]")["SubMenu"]["Count"];

but i dont know how make from value in arr correct [id] for this string.



Please help.




1 Reply

  • Hi,



    You cannot make this work because the Id value is not the one you should pass to Items as an index. These Ids have nothing to do with menu item indexes at all. In your case, the value you need instead of Id is the loop counter when you iterate through menu items and get their submenus.