Page 1 of 1
Changing a components text via buit-in functions.
Posted: Wed Nov 03, 2021 2:40 pm
by jay_dee
Hi,
If I have a series of static text components on a 2D panel.
Can I progmatically work through these items and change the text value?
(I know I could just update each box individually via a component call but I might have 30+ text boxes and it get a bit long winded)
I think... given Components
text1
text2
text3
I can build a string value, which indexes through these component Handle names,
calling the resulting string from within a 'built-in function'
for static text on a 2D panel, should I be using component|property|setvalue ?
handle: text1
property: text
value: "NewText"
new appraoch mean lots of learning and lots of questions!
Re: Changing a components text via buit-in functions.
Posted: Wed Nov 03, 2021 3:02 pm
by Steve-Matrix
Yes - use that SetValue built-in function. The first parameter is a "handle" to a component, but you can also pass the name of the component as a string (and this string can be a literal string or a string variable).
Re: Changing a components text via buit-in functions.
Posted: Wed Nov 03, 2021 6:58 pm
by jay_dee
Hi,
Simple example attached but cant get it working as expected... I think I am naming something incorrectly. I've checked capitalisation.
any pointers appreciated.
J.
Re: Changing a components text via buit-in functions.
Posted: Thu Nov 04, 2021 10:21 am
by BenR
Hello,
Here you go this should work better now and shows a few different ways to do things.
You can see the property variable name by selecting the property and the name is shown at the bottom of the property window, it is the variable you need to reference and so in this case the variable is "sText".

- Text.png (11.08 KiB) Viewed 5329 times
Re: Changing a components text via buit-in functions.
Posted: Thu Nov 04, 2021 1:47 pm
by jay_dee
Thanks, thats helped lots.
a)
But can I programically manipulate a handle name? I guess I can NOT create a handle of the same name as that which already exists, however....
I would like to be able to feed a built-in-function with a series of sequential handle names.
Is there a way to progmatically insert 'text1', text2, text3 etc into built-in-function that requires a handle parameter.
with a normal string I could do a loop and just add a character to the root name.
MyString = MyString + "1"
b) I never before paid attention to that lowest section of the panel showing the "properties of a property" - Great info.
c) Handles have their own variable type but can be created as you would add a normal variable. setting to "Object handle"
I see there is also a Built-in-function that also allows you to create a handle.
Re: Changing a components text via buit-in functions.
Posted: Thu Nov 04, 2021 2:12 pm
by Steve-Matrix
a) You can have something like "MyString = "text" + ToString$(index)" where 'index' is an integer variable that you increment each time.
c) You can pass a string instead of a handle to that function. The function internally converts a string to a handle for you.
Re: Changing a components text via buit-in functions.
Posted: Thu Nov 04, 2021 3:14 pm
by jay_dee
Thanks Ben and Steve,
I've got a better understanding of that now.
I've smashed together an improved rough example showing the various techniques discussed, it might help someone else.
J.