You are here: Core Reference > Coding > Scripting > Menu.AddMenu

Menu.AddMenu

The Menu.AddMenu function allows a script to add a submenu to a context sensitive menu.

Syntax

Menu.AddMenu(Text)

Description

Adds a submenu to the menu.

The Index Numbers of a menu and its submenus are numbered from top to bottom, with the next number in the sequence allocated to the next selectable option, irrespective of whether it is on a menu or on a submenu.

The Index Number 0 is reserved for the user quitting the menu without selecting an option.

Arguments

Text.

The string is the text that is shown for the submenu. This can be any string of characters enclosed in double quotes " "

Example:

The following script is used to add a submenu to a menu. The submenu contains 3 options (each option represents an increment of 10 and could be used to set the value of a point):

  • Public Function PointControlMenu
  • Dim Submenu
  •  
  • Menu.Init
  • Set Submenu = Menu.AddMenu("Set Value for Point A1")
  • Submenu.AddItem("10")
  • Submenu.AddItem("20")
  • Submenu.AddItem("30")
  •  
  • Menu.Display
  • End Function

Where:

  • Dim Submenu defines the name of the variable that is used to store the Control Object that is returned by the AddMenu function. In this case, the variable is named Submenu.
  • Menu.Init creates the menu
  • Set Submenu = Menu.AddMenu("Set Value for Point A1") creates the submenu and sets the Control Object to be stored in the Submenu variable
  • Submenu.AddItem("10") adds the first option to the submenu. It is named "10"
  • Submenu.AddItem("20") adds the second option to the submenu. It is named "20"
  • Submenu.AddItem("30") adds the third option to the submenu. It is named "30"
  • Menu.Display sets the menu to be displayed.


Two more options are added to the top-level menu:

  • Menu.AddItem("Display Controls Point A1")
  • Menu.AddItem("Display Notes Point A1")

This means that the menu options are allocated the following Index Numbers:

  • Display Controls Point A1—Index Number 1 as it is at the top of the menu
  • Display Notes Point A1—Index Number 2 as it is second in the menu (from top to bottom)
  • 10—Index Number 3 as it is third in the menu (from top to bottom). 10 is a submenu option and is numbered in the same way as the top level menu options. The option for the submenu ('Set Value for Point A1') does not have an Index Number as it does not return a value.
  • 20—Index Number 4
  • 30—Index Number 5

The AddMenu function adds the menu options and returns the index of the selected option only; it does not define the functionality of the options (the functionality can be defined using other functions such as the server functions after the Menu.Display function in the script).


ClearSCADA 2015 R2