Page 1 of 1
work with lines of field
Posted: Tue Aug 26, 2014 6:40 pm
by alberto.fre
Hi,
I have a doubt:
my program works by step:
1) the user insert some numbers
2) the program puts the numbers into some lines of a field
3) the program calculates the average
?) i want to calculate the standard deviation; the syntax is "standardDeviation (a,b,c)" but how i can insert "a,b,c"?
I don't know how operate with the lines of a field
My code doesn't work
Code: Select all
put the number of lines of field "numero" into tLines
repeat with i = 1 to tLines
put standardDeviation (line i of fld "numero") into devStandard
end repeat
Re: work with lines of field
Posted: Tue Aug 26, 2014 6:52 pm
by Klaus
Hi lberto,
so the lines of your field "numero" contain the correct values like:
1,2,3
4,5,6
7,8,9
etc...?
If yes, you can use ITEMS, the default item delimiter is already COMMA, so you can do something like this:
Code: Select all
...
## Avoid accessing FIELDS in repeat loops, this is a big speed-killer :-)
## put the number of lines of field "numero" into tLines
put fld "numero" into tText
put the number of lines of tText into tLines
repeat with i = 1 to tLines
## Get the values feom the line and put the into variables
## Will of course only work if ALL lines have at lest 3 items!
put line i of tText into tLine
put item 1 of tLine into tA
put item 2 of tLine into tB
put item 3 of tLine into tC
put standardDeviation (tA,tB,tC) into devStandard
end repeat
...
But this will overwrite the content of devStandard in every loop, so only the standardDeviation
of the LAST line of your field will be in devStandard after the loop!
Is that what you want?
Best
Klaus
Re: work with lines of field
Posted: Tue Aug 26, 2014 6:56 pm
by bangkok
standardDeviation needs a list (numbers separated by comma).
What does line 1 of fld "numero" contain ?
Your script is good... provided that line 1 of field "numero" contains for instance :
12,65,78,36
I'm guessing that your field contains actually a number PER line..
so in this case :
Code: Select all
put field "numero" into tData
replace cr with "," in tData
put standardDeviation (tData) into devStandard
answer devStandard
Re: work with lines of field
Posted: Tue Aug 26, 2014 7:42 pm
by alberto.fre
thank you for the replies
your field contains actually a number PER line
yes
now I'll try using your suggests
bye
Alberto
Re: work with lines of field
Posted: Tue Aug 26, 2014 7:52 pm
by alberto.fre
works fine, thank you very much.
I've got an other doubt:
there is a shorter way to return the data from many fields into one, separated by a comma or a newline.
My solution is not very elegant and is very long
thank you
Code: Select all
put field "1a" into field "numero"
put field "2a" into line 2 of field "numero"
put field "3a" into line 3 of field "numero"
put field "4a" into line 4 of field "numero"
put field "5a" into line 5 of field "numero"
put field "6a" into line 6 of field "numero"
put field "7a" into line 7 of field "numero"
put field "8a" into line 8 of field "numero"
put field "9a" into line 9 of field "numero"
put field "10a" into line 10 of field "numero"
put field "11a" into line 11 of field "numero"
put field "12a" into line 12 of field "numero"
put field "13a" into line 13 of field "numero"
put field "14a" into line 14 of field "numero"
put field "15a" into line 15 of field "numero"
put field "16a" into line 16 of field "numero"
put field "17a" into line 17 of field "numero"
put field "18a" into line 18 of field "numero"
put field "19a" into line 19 of field "numero"
put field "20a" into line 20 of field "numero"
put field "21a" into line 21 of field "numero"
put field "22a" into line 22 of field "numero"
put field "23a" into line 23 of field "numero"
put field "24a" into line 24 of field "numero"
put field "25a" into line 25 of field "numero"
put field "26a" into line 26 of field "numero"
put field "27a" into line 27 of field "numero"
put field "28a" into line 28 of field "numero"
put field "29a" into line 29 of field "numero"
put field "30a" into line 30 of field "numero"
Re: work with lines of field
Posted: Tue Aug 26, 2014 8:08 pm
by Klaus
Hi Alberto,
like this:
Code: Select all
...
##
lock screen
put field "1a" into tText
repeat with i = 2 to 30
## Create (concatenate) correct name of your target fields and put all text into a variable first!
put CR & fld ("a" & i) AFTER tText
end repeat
## Remove trailing CR:
delete char -1 of tText
## Now put variable "en bloc" into the field, this is much faster than filling the field line by line!
put tText into fld "numero"
unlock screen
...
Best
Klaus
Re: work with lines of field
Posted: Tue Aug 26, 2014 8:46 pm
by alberto.fre
thank you very much.