[Closed] (noob) convert strings to variable?
Yey! thanks a zillion Rens! I (we) fixed the problem!
here’s the fixed code line for event bname
on bname changed text do
(
obj_txt = bname.text as string
apply.enabled = on
execute (“foo = $’” + obj_txt + “’“)
if foo != undefined do select foo
if bname.text as string == “” then
(
deselect $
apply.enabled = off
)
global foo
)
one reason why my code want working a while ago is that i accidentally changed the macroscript category name, so I was running the same broken script (thru short-cut keys) all the time! whew!
And the SPACE problem was also fixed, by adding ’ (apostrophe) to the execute line.
Thanks for everyone who helped!
OK. Here is the solution to that space problem.
Replace execute (“foo = $” + obj_txt + “*”) with:
try
(
execute (“foo = $” + obj_txt + “*”)
)
catch
(
messageBox “Touch the space bar again.
I dare you.” title:“Error”
hold = filterString obj_txt ” “
if hold != undefined then
(
bname.text = hold[1]
)
else
(
bname.text = “”
)
)
[font=Verdana][color=White]
What this does is it catches all errors and runs a few lines when that happens. The text of the editText will be sorted by spaces, the first resulting array will be the new text. If the array is empty then the resulting text will be “”.
Basically this makes it impossible to get any spaces in.
- R
[/color][/font]
Argh, late again.
An apostrophe eh? Hmm, how does that fix the problem? Will it also work with multiple spaces?
Whoops.
if hold != undefined then
should be
if hold[1] != undefined then
[color=White][font=Verdana]Well. That should finally do it.
[/color][/font]
waw rens! that code is cool! im really learning a lot of stuff now!
oh, about the apostrphe, ive read about variable when selecting…
max said I cud call an object named Object Name by:
$object_name
or
$‘object name’
oh, thnx again about giving me solutions, i havent tried using try and catch, i guess ill start with your example.
Ah, I missed the first apostrophe. You’re right, box_01 is the same as ‘box 01’. That’s also a very good solution.
Good luck.
- R
The execute statement is nice, but it’s better to use something else if possible, as it’s a relatively slow function… So in your case, consider using either matchPattern or getNodeByName… See the online reference for more info on these.
- Martijn
allright!! those two simple codes are cool!! thanks again magicm!!:bounce: