0

In FactoryTalk View SE I’m trying to set an objects name in VBA based on another value.

This works:

Dim PumpSP As Object

Set PumpSP = ThisDisplay.PumpSetpoint1

PumpSP.Vaule = 10

This doesn’t work:

Dim PumpSP As Object

Set PumpSP = "ThisDisplay.PumpSetpoint" & "1"

PumpSP.Vaule = 10

How do I get it to take a concatenated string?

Thanks.

8
  • Any chance we can take a step back and explain what the broader goal is here? Commented Oct 29, 2018 at 18:18
  • try some thing like this Set PumpSP.name = "ThisDisplay.PumpSetpoint" & "1" Commented Oct 29, 2018 at 18:20
  • 1
    I'm unfamiliar with FactoryTalk View, but you can't access a member of an object with a string like that. I suspect what you need to do is loop over whatever collection you would find PumpSetpoint1 in to find it. Commented Oct 29, 2018 at 18:20
  • urdearboy - thanks for the format edit, I was trying to do that when you did it for me. Commented Oct 29, 2018 at 18:23
  • Adding ".Name" breaks it. :( Commented Oct 29, 2018 at 18:28

2 Answers 2

2

How do I get it to take a concatenated string?

You don't, and you can't. PumpSP is an Object, not a String. The only thing you can ever Set it to, is an object reference.

This is very similar to, say, how you would access the controls on a UserForm:

Set box = Me.TextBox1

The reason you can get that object with a string, is because a form has a Controls collection that lets you provide a string, works out which control has that name, and returns the Control object for it:

Set box = Me.Controls("TextBox" & i)

So in your case to go from this:

Set PumpSP = ThisDisplay.PumpSetpoint1

I don't know what ThisDisplay is, but maybe it has a similar collection:

Set PumpSP = ThisDisplay.Controls("PimpSetpoint" & i)

If there's no collection that lets you retrieve items by name with a string literal, you're out of luck.

Sign up to request clarification or add additional context in comments.

6 Comments

@Tanquen You need to look into your API (specifically ThisDisplay and see what's available there. Look for a collection property of some sort. Reference the type library, then hit F2 for the Object Browser. This is specific to the API you're using, not VBA. I can't help you any more than that, I don't know anything about ThisDisplay and your post doesn't include any hint whatsoever about what it might be.
All the objects are there in VBA but nothing popups for Controls. So I guess I have to loop through them all but I'm not having any luck with the syntax for it. ` For Each Item In ThisDisplay If Item.Name Like "PumpSetpoint1" Then Item.Value = 10 End If Next Item
Notice how I've mentioned several times that I know nothing about the API you're using, so it's entirely possible there's no .Controls member. This answer isn't telling you to do .Controls either - it's telling you to look for a collection property in your API. If ThisDisplay.Item(i) is valid, then maybe ThisDisplay.Item("PimpSetpoint" & i) is worth a shot?
Sorry, fist time posting and I can't even get the format in the comment to work. :(
Notice I’m trying and I was typing my last reply while you had posted yours. I know little of VBA. - In the Object Browser there is no "Controls" Member for the ThisDisplay class, no “Item” either if that matters. Not sure where ThisDisplay.Item(i) would be tested. Also, its PUMP not PIMP. :) It looks like a For each loop is the way to go but I can't get it to work.
|
0

That is the hard part as we have paid support with Rockwell but they will not help with any VBA questions. Ok fine but there VBA commands and class are not like 90% of the Excel or MS Office VBA you find online. Anyway I was able to find the correct class member.

So this work for me: Set PumpSP = ThisDisplay.FindElement("PumpSetpoint" & “1”) Thanks for all the help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.