|
|
Rank: Newbie Groups: Member
Joined: 10/13/2011 Posts: 4 Location: Rotterdam, The Netherlands
|
Hello,
I've created a processbook display that contains 30 textboxes (MS Forms 2.0 Textbox). I want to do the same code on all textboxes but i do not want to write this code over and over again. Therefor it would be nice to be able to loop through all textboxes on the display. In excel it would be easy to do but in Processbook I am not succesfull.
Is there a way to loop through all textboxes on a display?
Thanks in advance.
Ruud
|
|
|
|
|
OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System. We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ or contact OSIsoft vCampus for more details.
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
Try this, you could also find this is the VBA Help section in ProcessBook
Sub BLABLA()
For Each Symbol In ThisDisplay.Symbols If TypeName(Symbol) = "PBControl" Then If TypeName(Symbol.Object) = "TextBox" Then Debug.Print Symbol.Name End If End If Next End Sub
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
One additional comment to squatty's post...be sure your variable declaration uses the correct text box in ProcessBook when manipulating it. e.g. Use: Dim tb as MSForms.Textbox Not: Dim tb as Textbox Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 10/13/2011 Posts: 4 Location: Rotterdam, The Netherlands
|
Hi guys, thanks for the answers. I am now able to determine the amount of textboxes on my display but I am unable to set the textproperty. My code looks like this: Code: For Each smbl In ThisDisplay.Symbols If Left(smbl.Name, 3) = "txt" Then 'Textbox to manipulate found smbl.Text = "Get value from PI" End If Next
I get a 'runtime error 438: Object doesn't support this property' Anyone got some more tips? Thanks
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
Try: Code: For Each smbl In ThisDisplay.Symbols If Left(smbl.Name, 3) = "txt" Then 'Textbox to manipulate found Dim tb as MSForms.Textbox Set tb = smbl tbl.Text = "Get value from PI" End If Next
I would check the Symbol type in addition to a naming convention of your symbols that are prefixed "txt". Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Newbie Groups: Member
Joined: 10/13/2011 Posts: 4 Location: Rotterdam, The Netherlands
|
RJK Solutions wrote:Try: Code: For Each smbl In ThisDisplay.Symbols If Left(smbl.Name, 3) = "txt" Then 'Textbox to manipulate found Dim tb as MSForms.Textbox Set tb = smbl tb.Text = "Get value from PI" End If Next
I would check the Symbol type in addition to a naming convention of your symbols that are prefixed "txt". Unfortunately this does not work either :( Gives me a runtime error 13: Type mismatch. Code: Dim tb As MSForms.TextBox For Each Symbol In ThisDisplay.Symbols If Left(Symbol.Name, 3) = "txt" Then Debug.Print Symbol.Name 'Textbox to manipulate found Set tb = Symbol tb.Text = "Get value from PI" End If Next
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
Try this. Code: Sub BLABLA()
For Each Symbol In ThisDisplay.Symbols If TypeName(Symbol) = "PBControl" Then If TypeName(Symbol.Object) = "TextBox" Then Symbol.Object.Text = "TEST 123" End If End If Next End Sub
Be carefull to use the name of the symbol/object, in your case you are using "txt" so search for objects, by default when you add a new textbox control it will be named Textbox1, so each and everytime you add something new you have to rename the symbol, or you have to copy and paste an existing textbox to keep with the naming convention you have.
|
|
|
Rank: Newbie Groups: Member
Joined: 10/13/2011 Posts: 4 Location: Rotterdam, The Netherlands
|
squatty wrote:Try this. Code: Sub BLABLA()
For Each Symbol In ThisDisplay.Symbols If TypeName(Symbol) = "PBControl" Then If TypeName(Symbol.Object) = "TextBox" Then Symbol.Object.Text = "TEST 123" End If End If Next End Sub
Be carefull to use the name of the symbol/object, in your case you are using "txt" so search for objects, by default when you add a new textbox control it will be named Textbox1, so each and everytime you add something new you have to rename the symbol, or you have to copy and paste an existing textbox to keep with the naming convention you have. Thanks so much Squatty, this works perfect! I was not able to figure out how to make this work with the symbols-class but this is excellent.
|
|
|
|
Guest
|