Article ID: 162249
Article Last Modified on 6/29/2004
Class Name: tbrTest Based On: Toolbar Store In: Test.VCXClick OK.
** ToolBar tbrTest Init event ** aArray2 is dimensioned as a new property of the ** tbrTest ToolBar class. THIS.aArray2(1) = "Newspapers" THIS.aArray2(2) = "Magazines" THIS.aArray2(3) = "Radio" THIS.aArray2(4) = "Television" THIS.aArray2(5) = "Cable" THIS.aArray2(6) = "Direct Mail" THIS.aArray2(7) = "the Internet" THIS.aArray2(8) = "Billboards" THIS.aArray2(9) = "Telemarketing" THIS.aArray2(10) = "Word-of-mouth" ** The next 3 lines populate Combo2 using the AddItem method. i = 0 FOR i = 1 to ALEN(THIS.aArray2) THIS.Combo2.AddItem(This.aArray2(i)) NEXT ** The next 3 lines populate Combo3 using the properties ** of that ComboBox. THIS.Combo3.RowSourcetype = 5 && Type Array THIS.Combo3.RowSource = "THIS.Parent.aArray2" ** The code uses the string at the right in the line above ** in the Requery method of the Combo as the RowSource ** for the Combo. THIS.Combo3.Requery ******** End of tbrTest Init Event ********
*** Init event code for formset frsTest ***
IF TYPE("THIS.form1") = "O" && Ensures the form is instantiated.
THIS.tbrTest.left = THIS.form1.left
THIS.tbrTest.top = THIS.form1.top - (THIS.tbrTest.height + 25)
ENDIF
THIS.aArray1(1) = "This is 1"
THIS.aArray1(2) = "This is 2"
THIS.aArray1(3) = "This is 3"
THIS.aArray1(4) = "This is 4"
THIS.aArray1(5) = "This is 5"
THIS.tbrTest.Combo1.AddItem(THIS.aArray1(5))
THIS.tbrTest.Combo1.AddItem(THIS.aArray1(4))
THIS.tbrTest.Combo1.AddItem(THIS.aArray1(3))
THIS.tbrTest.Combo1.AddItem(THIS.aArray1(2))
THIS.tbrTest.Combo1.AddItem(THIS.aArray1(1))
*** End if frsTest Init event code ***
*************************************************
** tbrTest.prg
** Sample program to populate ComboBoxes in
** a ToolBar.
*************************************************
DIMENSION aFifthArray(10,1)
aFifthArray(1) = "Boston"
aFifthArray(2) = "Providence"
aFifthArray(3) = "New Haven"
aFifthArray(4) = "Armonk"
aFifthArray(5) = "Grand Central"
Dimension aSixthArray(10,1)
aSixthArray(1) = "James"
aSixthArray(2) = "Charles"
aSixthArray(3) = "Hudson"
aSixthArray(4) = "Rapahoneck"
aSixthArray(5) = "Catawba"
aSixthArray(6) = "Susquehanna"
aSixthArray(7) = "Cooper"
aSixthArray(8) = "Pee Dee"
aSixthArray(9) = "Neuss"
aSixthArray(10) = "Ohio"
MyFormset = CREATEOBJECT("FormSet")
WITH MyFormset
.AddObject("tbrTools1", "tbrTest")
.AddObject("Myform", "form1")
WITH .myform
.AddObject("quitter", "cmdClose")
WITH .Quitter
.top = 150
.left = 200
.visible = .T.
ENDWITH
.top = 100
.left = 10
.visible = .T.
ENDWITH
WITH .tbrTools1
.top = myformset.myform.top - 60
.Left = myformset.myform.left
.visible = .T.
WITH .Combo5
.AddItem(aFifthArray(1))
.AddItem(aFifthArray(2))
.AddItem(aFifthArray(3))
.AddItem(aFifthArray(4))
.AddItem(aFifthArray(5))
ENDWITH
WITH .Combo6
.RowSourcetype = 5
.RowSource = "aSixthArray"
.Requery
ENDWITH
ENDWITH
ENDWITH
READ EVENTS
DEFINE CLASS form1 AS FORM
Height = 100
Width = 500
Top = 100
Left = 10
ADD OBJECT cmdQuit as cmdClose
ENDDEFINE
DEFINE CLASS cmdClose AS CommandButton
Height = 29
Width = 50
Caption = "\<Close"
PROCEDURE Click
ThisFormSet.Release
CLEAR EVENTS
ENDPROC
ENDDEFINE
DEFINE CLASS tbrTest AS TOOLBAR
ADD OBJECT Combo1 AS COMBOBOX
ADD OBJECT Combo2 AS COMBOBOX
ADD OBJECT Combo3 AS COMBOBOX
ADD OBJECT Combo4 AS COMBOBOX
ADD OBJECT Combo5 AS COMBOBOX
ADD OBJECT Combo6 AS COMBOBOX
* Start of the class defInition: one ToolBar with 6 ComboBoxes.
Left = 1
Top = 1
Width = 575
Caption = "Test ToolBar #2"
Combo1.Height = 27
Combo1.Width = 82
Combo2.Height = 27
Combo2.Width = 82
Combo3.Height = 27
Combo3.Width = 82
Combo4.Height = 27
Combo4.Width = 82
Combo5.Height = 27
Combo5.Width = 82
Combo6.Height = 27
Combo6.Width = 82
PROCEDURE Load
* ComboBox2 does not exist at Load time.
Dimension gaArray1(10,1)
gaArray1(1) = "Arkansas"
gaArray1(2) = "Colorado"
gaArray1(3) = "Delaware"
gaArray1(4) = "Georgia"
THIS.Combo2.AddItem(This.gaArray1(1))
THIS.Combo2.AddItem(This.gaArray1(2))
THIS.Combo2.AddItem(This.gaArray1(3))
THIS.Combo2.AddItem(This.gaArray1(4))
ENDPROC
* Sets properties of the controls.
* Notice that there are no Top or Left property settings for
* controls on a ToolBar. Controls on a ToolBar are automatically
* positioned in the order they are added.
PROCEDURE Activate
* ComboBox1 is populated within the activate procedure of the ToolBar.
THIS.Combo1.AddItem("This is item 1")
THIS.Combo1.AddItem("This is item 2")
THIS.Combo1.AddItem("This is item 3")
THIS.Combo1.AddItem("There are no more")
* ComboBox2 is populated from array elements declared
* and populated in the Load event of the ToolBar, but this code is
* run before the ToolBar is loaded, so it causes the error "Property
* 'GARALPHARRAY' is not found."
*THIS.Combo2.AddItem(This.gaArray1(1))
*THIS.Combo2.AddItem(This.gaArray1(2))
*THIS.Combo2.AddItem(This.gaArray1(3))
*THIS.Combo2.AddItem(This.gaArray1(4))
* The following code depends upon the formset having a
* gaSomeArray() defined and populated, but it suffers from the same
* problem as the code immediately above, and causes the error
* "Property 'GASOMEARRAY' is not found."
*THIS.Combo3.AddItem(THISFORMSET.gaSomeArray(1))
*THIS.Combo3.AddItem(THISFORMSET.gaSomeArray(2))
*THIS.Combo3.AddItem(THISFORMSET.gaSomeArray(3))
*THIS.Combo3.AddItem(THISFORMSET.gaSomeArray(4))
DIMENSION gaArray4(10,1)
gaArray4(1) = "Seattle"
gaArray4(2) = "Portland"
gaArray4(3) = "San Francisco"
gaArray4(4) = "Los Angeles"
gaArray4(5) = "San Diego"
THIS.Combo4.AddItem(gaArray4(1))
THIS.Combo4.AddItem(gaArray4(2))
THIS.Combo4.AddItem(gaArray4(3))
THIS.Combo4.AddItem(gaArray4(4))
THIS.Combo4.AddItem(gaArray4(5))
* ComboBox5 is populated from program code run after the
* formset is loaded, Initialized, and populated, from an
* array declared and Initialized before the formset is
* created.
ENDDEFINE && End of ToolBar class defInition
(c) Microsoft Corporation 1997, All Rights Reserved.
Contributions by Chris Jensen, Microsoft Corporation
Keywords: kbhowto kboop kbcode KB162249