Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I have a number of fields in my group and i have a variable.
I want to rename each field inside the group with the names from variable.
but with the bellow code i can make it to work
put the keys of tArray[response] into tKeys
repeat with x=1 to the number of fields of group "grp1"
add 1 to counter
put line 1 of tkeys into f
delete line 1 in tKeys
if the disabled of fld x of group "grp1"is true then
set the name of fld x of group "grp1" to f
set the text of fld x of group "grp1" to f
end if
end repeat
end mouseUp
my array looks like this
Array[response]
and the keys
Last edited by brandcode on Sat Mar 28, 2015 6:16 pm, edited 1 time in total.
Why an array? Anyway, I did not test your code, but what is different between your approach and the following button script. I made a group of fields on a new card.
Why an array? Anyway, I did not test your code, but what is different between your approach and the following button script. I made a group of fields on a new card.
on mouseUp
put "newName" into f
repeat with y = 1 to the number of flds of grp 1
set the name of fld y of grp 1 to f & y
end repeat
end mouseUp
Just an aside, it is very important to reference the group in the "set" line. Do you know why?
Craig Newman
hi Craig thank you for the fast reply.
Array because is coming from json parse, and the key names is random.
Group with fields because the number of fields is random ,maybe 5 fields or 20 depend from json parse.
So when i do the repeat in array that line will be the name of the field.
Just an aside, it is very important to reference the group in the "set" line. Do you know why?
yes because if i don't set will be change the fields outside of the group ?
But does your handler work? Are you asking for help or just posting for comments?
Craig
until now is no working.
in the line 3 ( put tLine into f) i get always the same name like "test1"
And with the delete in line 5 still can read the next line in my array.
i think because is the repeat inside the repeat?
I am a confuse with the repeat command.i am sure is something wrong with my code..
I want to get each line from array A and rename each name in the fields with array name.
It sometimes is intrinsically bad to delete lines of a working dataSet starting from the top, following some process. It is just the way we count the integers. This usually pops up when an indexed repeat is running, (repeat with...).
Is it possible that something similar is happening here as well, as Sparkout alluded to? If you step through the handler, does the number of lines and their order keep to your intent?
Why did you edit the code in the original post?
I think you had it nearly right in the first place there, but when deleting the first line of the keys in the loop you threw it out.
I think. I am still not quite sure what you were expecting, although your edit makes me think you were originally on the right lines a little more. But can you explain which field names should be changed? Only change the corresponding field number with the corresponding key line number? (It is very dangerous to rely on the order of an array's keys without specifically sorting them.)
SparkOut wrote:Why did you edit the code in the original post?
I think you had it nearly right in the first place there, but when deleting the first line of the keys in the loop you threw it out.
I think. I am still not quite sure what you were expecting, although your edit makes me think you were originally on the right lines a little more. But can you explain which field names should be changed? Only change the corresponding field number with the corresponding key line number?
my array have 10 keys like bellow,and i want only the key name
and in the group with fields i have 10 fields with No Name on them (label 1,etc)
so the result i want, is to get the key name from the array, and rename all the field (names)
But do you want all the field names to change to the same thing?
Presumably you have an array such as:
tArray["NameOne"] with value "Data1"
tArray["NameTwo"] with value "Data2" etc. etc.
So guessing you want field 1 of the group to have its name set to "NameOne" and field 2 of the group to have the name set to "NameTwo" and so on, is that right?
Because unless you are able to SORT the keys of the array to a corresponding order for the fields in the group to match the field number, you will have a problem, as the keys for an array may be retrieved in any arbitrary order.
SparkOut wrote:But do you want all the field names to change to the same thing?
Presumably you have an array such as:
tArray["NameOne"] with value "Data1"
tArray["NameTwo"] with value "Data2" etc. etc.
So guessing you want field 1 of the group to have its name set to "NameOne" and field 2 of the group to have the name set to "NameTwo" and so on, is that right?
Because unless you are able to SORT the keys of the array to a corresponding order for the fields in the group to match the field number, you will have a problem, as the keys for an array may be retrieved in any arbitrary order.
Yes you have right.
field 1 = NameOne
field 2 NameTwo
etc.
No problem about the sorting.