Retrieving parameter value with parameter name as string
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2016-06-03 05:52 AM
‎2016-06-03
05:52 AM
I have a parameter called
param_1which is a boolean variable
I then generate the parameter name in a loop
ie.
i = 0 FOR i=1 TO 6 STEP 1 mystring = 'param_' + str(i,1,0) NEXT iI then want to use the generated param name in the same loop
( mystring = "param_1" )
(which does not work)
i = 0 FOR i=1 TO 6 STEP 1 mystring = 'param_' + str(i,1,0) if mystring = 1 Then ! // code related to if checkbox is checked (TRUE/ON/1) else ! // code related to if checkbox is NOT checked (FALSE/OFF/0) endif NEXT iThe code below does work!!
i = 0 FOR i=1 TO 6 STEP 1 mystring = 'param_' + str(i,1,0) UI_INFIELD mystrng, base_posx, base_posy, 20, 20 NEXT i
Given that I can use the generated parameter name with the UI_INFIELD command, I figured there must be a way to use it in an IF statement.
Could anyone point me in the right direction please?
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2016-06-03 09:30 AM
‎2016-06-03
09:30 AM
Matrices are your friend in this situation. You can't use a loop to create a variable name (as you can in other languages), but you can populate and query / test the contents of a matrix.
DIM arrayName[] is how you declare (or DIM arrayName[][] for a 2-dimension array)
Hope this helps.
DIM arrayName[] is how you declare (or DIM arrayName[][] for a 2-dimension array)
Hope this helps.
Bruce Walker
Barking Dog BIM YouTube
Mindmeister Mindmap
-- since v8.1 --
AC27 5060 INT Full | Windows 11 64 Pro | 12th Gen Intel i7-12700H 2.30 GHz | 64 Gb RAM | NVIDIA GeForce RTX 3060 32 Gb
Barking Dog BIM YouTube
Mindmeister Mindmap
-- since v8.1 --
AC27 5060 INT Full | Windows 11 64 Pro | 12th Gen Intel i7-12700H 2.30 GHz | 64 Gb RAM | NVIDIA GeForce RTX 3060 32 Gb
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2016-06-07 04:30 AM
‎2016-06-07
04:30 AM
Bruce wrote:Thanks for this Bruce,
Matrices are your friend in this situation. You can't use a loop to create a variable name (as you can in other languages), but you can populate and query / test the contents of a matrix.
DIM arrayName[] is how you declare (or DIM arrayName[][] for a 2-dimension array)
Hope this helps.
Ended up following this advice and just passing all the values from the parameters into an array that could be looped through.
It's a shame GDL can't handle parsing strings as param names, this work around works though!