Learn to manage BIM workflows and create professional Archicad templates with the BIM Manager Program.
2024-02-06
01:40 AM
- last edited on
2024-09-26
01:21 PM
by
Doreena Deng
Hi,
I am wondering if it is possible to change the variable name on the fly, e.g when calling from a Subroutine, having the variable name part1+part2 merged together. An example would be a variable called Var_A where the prefix is added to the suffix, like Len = "Var"+"_A".
This would be great as it would allow a single subroutine to have its parameters changed easily, from _A to _C etc, especially when there are quite a few options variables and keep the code small. Is this possible or is there a better way of making a simple repeating subroutine with different variable inputs?
For a code example in 2D Script:
option1 = 1
option2 = 1
option3 = 1
Var_A = 0.010
Var_B = 0.015
Var_C = 0.020
IF option1 = 1 THEN
Suffix = "_A"
Len = "Var"+Suffix
Offset = 0.01
Gosub "CircleTest":
ENDIF
IF option2 = 1 THEN
Suffix = "_B"
Len = "Var"+Suffix
Gosub "CircleTest":
ENDIF
IF option3 = 1 THEN
Suffix = "_C"
Len = "Var"+Suffix
Gosub "CircleTest":
ENDIF
END
!*************************************
"CircleTest": !Gosub Reference
Circle2 0,0,Len
RETURN
Ideally this should return three circles, but it comes up with an error.
Is there a way to string together the suffix to a common prefix?
Many thanks, Matt
Solved! Go to Solution.
2024-02-08 10:20 AM
You can even use:
GOSUB 1000 + GLOB_SCALE
END
1050:
RETURN
I think the difference is, that with CIRCLE2 there should be the Variable name composed with different parts, while in my examples the Value of the variables are composed of different parts.
I am sorry for the confusion.
2024-02-08 10:30 AM
But the original poster wanted to join two strings together to change the variable name, not the variable value.
So I think this is going a bit off topic, although it is good to know these techniques.
Barry.
2024-02-08 12:26 PM
There are actually also situations in which the variable name can consist of compound parts; namely in cases in which a variable or a parameter name within a GDL command is to be used as a string with quotation marks.
Example:
! Parameter 1 = qay_1, Parameter 2 = qay_2
UI_INFIELD "qay_" + STR(1, 1, 0), 20, 20, 100 , 20
UI_INFIELD "qay_" + STR(2, 1, 0), 20, 50, 100 , 20