Field number in a group

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: Field number in a group

Post by paulclaude » Thu May 23, 2019 5:37 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Field number in a group

Post by dunbarx » 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

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: Field number in a group

Post by paulclaude » Thu May 23, 2019 6:56 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Field number in a group

Post by jacque » 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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Field number in a group

Post by FourthWorld » 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: Field number in a group

Post by paulclaude » Sat May 25, 2019 2:09 pm

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.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Field number in a group

Post by [-hh] » 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.
shiftLock happens

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: Field number in a group

Post by paulclaude » Sat May 25, 2019 4:27 pm

[-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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Field number in a group

Post by jacque » Sat May 25, 2019 6:29 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Field number in a group

Post by bogs » Sun May 26, 2019 11:40 am

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 :twisted:

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.
Image

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: Field number in a group

Post by paulclaude » Sun May 26, 2019 12:54 pm

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 :wink:

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Field number in a group

Post by [-hh] » 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
shiftLock happens

paulclaude
Posts: 121
Joined: Thu Mar 27, 2008 10:19 am

Re: Field number in a group

Post by paulclaude » Mon May 27, 2019 8:16 pm

[-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

Post Reply