Applies To:
  • CitectSCADA 5.31, 5.40, 5.41, 5.42, 5.50, 6.0, 6.1, 7.0
  • CitectHMI 5.31, 5.40, 5.41, 5.42, 5.50, 6.0, 6.1, 7.0
  • CitectFacilities 5.31, 5.40, 5.41, 5.42, 5.50, 6.0, 6.1, 7.0
  • CitectSCADA Batch 5.31, 5.40, 5.41, 5.42, 5.50, 6.0, 6.1, 7.0
  • CitectSCADA Pocket 5.31, 5.40, 5.41, 5.42, 5.50, 6.0, 6.1, 7.0

Summary:

How do I create a combo box?

 

Solution:

There are 2 ways to do it, Use:

* ActiveX combo box, or
* ciText.combobox.

To use an ActiveX combo box:

Paste the activeX control “Microsoft Forms 2.0 ComboBox” on a graphics page
Associate the TEXT property with a Tag. This tag will contain the value of the item selected from the ComboBox.
FUNCTION MyPageLoad()
   OBJECT oComboBox1
   INT iIndex
   oComboBox1 = ObjectByName("AN210")
   _ObjectCallMethod(oComboBox1,"Clear")
   _ObjectCallMethod(oComboBox1,"AddItem","Tag1",iIndex)
   iIndex = iIndex + 1
   _ObjectCallMethod(oComboBox1,"AddItem","Tag2",iIndex)
   iIndex = iIndex + 1
   _ObjectCallMethod(oComboBox1,"AddItem","Tag3",iIndex)
END

FUNCTION MyPageLoad2()
   OBJECT oComboBox1
   INT iIndex
   oComboBox1 = ObjectByName("AN210")
   _ObjectCallMethod(oComboBox1,"Clear")
   _ObjectCallMethod(oComboBox1,"AddItem",Tag1,iIndex)
   iIndex = iIndex + 1
   _ObjectCallMethod(oComboBox1,"AddItem",Tag2,iIndex)
   iIndex = iIndex + 1
   _ObjectCallMethod(oComboBox1,"AddItem",Tag3,iIndex)
   iIndex = iIndex + 1
END

To use a ciText combo box:

  1. Use example project
  2. Paste the following function to Recipe.Ci file
  3. Configure a device using DBF file type (as we are using Example project, Recipe.dbf already exists)
  4. Insert CiText.ComboBox on a graphics page (Say page "Recipe")
  5. Find out the animation point occupied by this control
  6. Add a button on this page as well and call the following function in the command field LoadRecipe2ComboBox("AN35")
  7. Compile the project
  8. Run the project
FUNCTION LoadRecipe2ComboBox(STRING sAN)
   STRING sName;
   OBJECT oComboBox1;
   INT iComboBoxIndex1 = 0;
   INT iRecNo;
   IF hRecipe < 0 THEN
	hRecipe = DevOpen("Recipes", 0);
   END
   IF hRecipe >= 0 THEN
	iRecNo = DevRecNo(hRecipe); !Current Record Number
	DevSeek(hRecipe, 1);
	oComboBox1 = ObjectByName(sAN);
	_ObjectCallMethod(oComboBox1, "Clear");
	WHILE NOT DevEOF(hRecipe) DO
		 sName = DevGetField(hRecipe, "Name");
		 _ObjectCallMethod(oComboBox1, "AddItem", sName,
		 iComboBoxIndex1);
		 iComboBoxIndex1 = iComboBoxIndex1 + 1;
		 DevNext(hRecipe);
	END
	DevSeek(hRecipe, iRecNo); // Reinstate the original position
   ELSE
	Message("ComboBox", "Cannot Open Recipes.DBF device.", 0);
   END
END
If you want to use the function with other applications, you should modify it accordingly. For example, if you have more than one ComboBox on a page, you could code the function as generic one as shown below. Simply pass the device handle, animation point number and data field name. Note that you want the function to be call on page entry, you have to delay the call until the control is instantiated. In V6, a new page event called "On page shown" is introduced that guarantee all objects are instantiated. Hope this would help.
FUNCTION LoadRecipe2ComboBox(INT hRecipe, STRING sAN, STRING sFieldName)
   STRING sName;
   OBJECT oComboBox1;
   INT iComboBoxIndex1 = 0;
   INT iRecNo;
   IF hRecipe >= 0 THEN
	iRecNo = DevRecNo(hRecipe); !Current Record Number
	DevSeek(hRecipe, 1);
	oComboBox1 = ObjectByName(sAN);
	_ObjectCallMethod(oComboBox1, "Clear");
	WHILE NOT DevEOF(hRecipe) DO
		 sName = DevGetField(hRecipe, sFieldName);
		 _ObjectCallMethod(oComboBox1, "AddItem", sName,
		 iComboBoxIndex1);
		 iComboBoxIndex1 = iComboBoxIndex1 + 1;
		 DevNext(hRecipe);
	END
	DevSeek(hRecipe, iRecNo); // Reinstate the original position
   ELSE
	Message("ComboBox", "Cannot Open Recipes.DBF device.", 0);
   END
END
 

Keywords:
 

Attachments