Forum Discussion

sastowe's avatar
sastowe
Super Contributor
11 years ago

Testing for the existence of a MenuItem;s SubMenu

I have a MainMenu object. Some of the menu items have submenus and some don't.  How do I test whether or not there is a Submenu? In the debug window, it shows an object,  but there are no properties or methods, not even an Exists for items with no SubMenu?



I need to determine whether or not an item has a submenu.



Thanks



S

3 Replies

  • karkadil's avatar
    karkadil
    Valued Contributor
    Each menu item has SubMenu property which is empty (null) when menu item doesn't have submenu. For example, the following code will print to the log information about each menu item of the Notepad Main Menu.




    var wnd = Sys.Process("NOTEPAD").Window("Notepad", "Untitled - Notepad");


        for(var i = 0; i < wnd.MainMenu.Count; i++)


        {


          var caption = wnd.MainMenu.Items(i).Caption;


          if(wnd.MainMenu.Items(i).SubMenu == null)


          {


            Log.Message(caption + " menu doesn't have submenu");


          }


          else


          {


            Log.Message(caption + " menu has submenu");


          }

  • sastowe's avatar
    sastowe
    Super Contributor
    <head slap> I tested empty. I tested isObject. I did not test null. Idiot. :)



    Thanks



    S