YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Loop through textboxes on display Options · View
der_roedie
#1 Posted : Thursday, October 13, 2011 2:12:08 PM
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
Sponsor  
 

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.
squatty
#2 Posted : Friday, October 14, 2011 8:00:23 AM
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
RJK Solutions
#3 Posted : Friday, October 14, 2011 9:21:35 AM
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
der_roedie
#4 Posted : Monday, October 17, 2011 10:21:35 AM
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
RJK Solutions
#5 Posted : Monday, October 17, 2011 9:42:09 PM
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
der_roedie
#6 Posted : Tuesday, October 18, 2011 7:52:35 AM
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
squatty
#7 Posted : Tuesday, October 18, 2011 9:53:24 AM
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.
der_roedie
#8 Posted : Tuesday, October 18, 2011 9:59:21 AM
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.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.