GDL
About building parametric objects with GDL.
SOLVED!

Can two words be joined into a variable name?

GDL Enthusiast
Enthusiast

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

12 REPLIES 12
Jochen Suehlo
Advisor

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.

Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

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.

One of the forum moderators.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
Jochen Suehlo
Advisor

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
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!