Page 2 of 2
Re: Field number in a group
Posted: Thu May 23, 2019 5:37 pm
by paulclaude
bogs wrote: Thu May 23, 2019 4:58 pm
Then you need to learn to use and love childControlNames, because you are not looking for the number or layer of the field, but it's order within the group.
This
video may make it clearer for you, but in essence, to find the order of a control within a group within a group within yet ANOTHER group is no more difficult than figuring out its line number, which you can do with code from the previous post, and without a repeat loop.
Yes Bogs, I already use
Code: Select all
put lineOffset(fID,the childControlIDS of group lName of me) into fNum
to retrieve the field number. I can do it because I have only fields in the group, of course. Many controls (in the group) of different type with variable order make the trick useless.
Re: Field number in a group
Posted: Thu May 23, 2019 6:38 pm
by dunbarx
PaulClaude
Paul? Claude?
Anyway, it seems you have this in hand. So the topic really was a NATIVE way to:
Code: Select all
put the number of control targetControlReference of grp targetGroup
This sidesteps the issue of who owns who and knowing where your children are.
The good news is that LC invariably offers direct and straightforward ways around these sorts of things.
Craig
Re: Field number in a group
Posted: Thu May 23, 2019 6:56 pm
by paulclaude
dunbarx wrote: Thu May 23, 2019 6:38 pm
PaulClaude
Paul? Claude?
Anyway, it seems you have this in hand. So the topic really was a NATIVE way to:
Code: Select all
put the number of control targetControlReference of grp targetGroup
This sidesteps the issue of who owns who and knowing where your children are.
The good news is that LC invariably offers direct and straightforward ways around these sorts of things.
Craig
I'm Paul.
I thought there was some kind of function like
Code: Select all
put the {internal/order/child} number of fld ID 1234 of group...
It doesn't matter
Greetings
Re: Field number in a group
Posted: Fri May 24, 2019 5:07 pm
by jacque
I can do it because I have only fields in the group, of course. Many controls (in the group) of different type with variable order make the trick useless.
If you use the keyword "control" rather than "field" it will work for any object.
Re: Field number in a group
Posted: Fri May 24, 2019 5:51 pm
by FourthWorld
I have a hunch that if we knew more about the UI needing this very specific form of addressing we'd be able to come up with an optimal solution for it easily.
Re: Field number in a group
Posted: Sat May 25, 2019 2:09 pm
by paulclaude
jacque wrote: Fri May 24, 2019 5:07 pm
I can do it because I have only fields in the group, of course. Many controls (in the group) of different type with variable order make the trick useless.
If you use the keyword "control" rather than "field" it will work for any object.
Hi Jaqueline,
Thank you for your advice., but maybe you haven't had time to read the whole thread or maybe it's me who explains myself wrong in English (this is likely).
I try with another example:
I've a group within a group. This group contains fld a (layer 1),fld b(layer 2),btn a(layer 3),fld c(layer 4).
The command "select fld 3" actually select fld c.
The command "select control 3" actually select btn a.
I realized that there is no direct functions to obtain the order number (3, in my example) of fld c (knowing only its ID) in Livecode. There are a thousand workarounds, however.
Re: Field number in a group
Posted: Sat May 25, 2019 3:14 pm
by [-hh]
Assume you have a group "main" containing a group "test" that contains fld id 1101 (layer 1), fld id 1012 (layer 2), btn a (layer 3), fld id 1001 (layer 4).
Now use the single function
Code: Select all
function getFldNumberInGroup pNr
return 1 - (the number of fld 1 of the owner of fld id pNr) \
+ (the number of fld id pNr)
end getFldNumberInGroup
Then
Code: Select all
put getFldNumberInGroup(1001) into N -- yields 3
select fld N of group "test" of grp "main"
does what you want.
Re: Field number in a group
Posted: Sat May 25, 2019 4:27 pm
by paulclaude
[-hh] wrote: Sat May 25, 2019 3:14 pm
Assume you have a group "main" containing a group "test" that contains fld id 1101 (layer 1), fld id 1012 (layer 2), btn a (layer 3), fld id 1001 (layer 4).
Now use the single function
Code: Select all
function getFldNumberInGroup pNr
return 1 - (the number of fld 1 of the owner of fld id pNr) \
+ (the number of fld id pNr)
end getFldNumberInGroup
Then
Code: Select all
put getFldNumberInGroup(1001) into N -- yields 3
select fld N of group "test" of grp "main"
does what you want.
Thank you, I'll try it out.
Re: Field number in a group
Posted: Sat May 25, 2019 6:29 pm
by jacque
You're right, I was at the LC conference and didn't read the entire thread. Your English is very good so that wasn't a problem.
I think I'd use the method you use now, getting the line offset of the child controls. It seems the most straightforward way.
Re: Field number in a group
Posted: Sun May 26, 2019 11:40 am
by bogs
FourthWorld wrote: Fri May 24, 2019 5:51 pm
I have a hunch that if we knew more about the UI needing this very specific form of addressing we'd be able to come up with an optimal solution for it easily.
I have to say, I'm curious myself, because in side testing I've done if I "put" or "get" text into field x of group x, where x is an integer (no matter how nested apparently), it happens no matter how many other controls are in that group where there is a field x.
So if I have 4 fields and 6 buttons in group c of group b of group a (with more controls in a and b), and I write
Code: Select all
put "this text" into field 2 of group {c}
-- or
get field 4 of group {c}
It works as expected, and since I can't think of anything else you might be doing with a field, I'd really love to know just what it is you *are* doing that requires more
So far, the 'clues' we have are you don't want it in a repeat loop. To me, that suggests you have the number of the next field already, but aren't sure if there is a next field. Is that it?
paulclaude wrote: Sat May 25, 2019 2:09 pm
maybe it's me who explains myself wrong in English (this is likely).
I agree with Jacque, your english is fine, but unless it is a top government secret or something, please post what exactly you are trying to accomplish.
Re: Field number in a group
Posted: Sun May 26, 2019 12:54 pm
by paulclaude
bogs wrote: Sun May 26, 2019 11:40 am
I agree with Jacque, your english is fine, but unless it is a top government secret or something, please post what exactly you are trying to accomplish.
No top government secrets, Bogs, simply I wrote many applications in these years and, sometimes, I happened to want to refer to the number of a field (to find the next one, the previous one, without using names or properties, or similar things).
I've always used workarounds, but I was curious to know if there was a direct function in Livecode that I may never have considered.
Nothing more than this

Re: Field number in a group
Posted: Mon May 27, 2019 10:38 am
by [-hh]
Once again, there is a direct function: the number.
If you wish to have the number of a fld relative to its enclosing group then this is 1 + the difference of its number to the number of fld 1 of this enclosing group. So
Code: Select all
function getFldNumberInGroupByID pID
return 1 - (the number of fld 1 of the owner of fld id pID) \
+ (the number of fld id pID)
end getFldNumberInGroupByID
is what you want.
TMHO, this is still "direct", no "workaround", could be called the "relative number" of fld id x.
Of course you can get this "relative number" also when identifying fields by their number or name rather than by their short ID:
Code: Select all
function getFldNumberInGroupByName pN
return 1 - (the number of fld 1 of the owner of fld pN) + (the number of fld pN)
end getFldNumberInGroupByName
function getFldNumberInGroupByNumber pN
return 1 - (the number of fld 1 of the owner of fld pN) + pN
end getFldNumberInGroupByNumber
Re: Field number in a group
Posted: Mon May 27, 2019 8:16 pm
by paulclaude
[-hh] wrote: Mon May 27, 2019 10:38 am
Once again, there is a direct function: the number.
If you wish to have the number of a fld relative to its enclosing group then this is 1 + the difference of its number to the number of fld 1 of this enclosing group. So
Code: Select all
function getFldNumberInGroupByID pID
return 1 - (the number of fld 1 of the owner of fld id pID) \
+ (the number of fld id pID)
end getFldNumberInGroupByID
is what you want.
TMHO, this is still "direct", no "workaround", could be called the "relative number" of fld id x.
Of course you can get this "relative number" also when identifying fields by their number or name rather than by their short ID:
Code: Select all
function getFldNumberInGroupByName pN
return 1 - (the number of fld 1 of the owner of fld pN) + (the number of fld pN)
end getFldNumberInGroupByName
function getFldNumberInGroupByNumber pN
return 1 - (the number of fld 1 of the owner of fld pN) + pN
end getFldNumberInGroupByNumber
Once again, your suggestions are very good. I was asking for a native Livecode function (which does not exist). Thanks