How write lines of differents fields to the same file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How write lines of differents fields to the same file
Hi,
I'm a new user of revolution.
I have 6 different fields with lines in. I can't know the lines' number of each fields in advance.
I would write the first line of each field to the first line of an other field, the second line of each field to the second line of the "other field" and repeat this for each line of the 6 fields until they are empty.
Someone may help me, please ?
Vincent
I'm a new user of revolution.
I have 6 different fields with lines in. I can't know the lines' number of each fields in advance.
I would write the first line of each field to the first line of an other field, the second line of each field to the second line of the "other field" and repeat this for each line of the 6 fields until they are empty.
Someone may help me, please ?
Vincent
Hi Vincent,
I'm not really sure what it is you're trying to achieve, and what sort of data you are dealing with.
You have some fields, let's say:
Field1, Field2, Field3, Field4, Field5, Field6 and a FieldAggregate
Field 1 contains
A line of text
Another line of text
Some more text
Field 2 contains
1
2
3
4
5
6
Field 3 contains
Code1
Code2
Code3
Code4
etc. etc. for a variable number of lines of data in each field?
What is the expected result you need in FieldAggregate? To look like:where all the "line ones" are appended to each other in the aggregate field, separated by tabs (say)?
This would be quite simple, but I'm not at all sure it's what you're trying to do. Can you give a more detailed example of how you want the result?
I'm not really sure what it is you're trying to achieve, and what sort of data you are dealing with.
You have some fields, let's say:
Field1, Field2, Field3, Field4, Field5, Field6 and a FieldAggregate
Field 1 contains
A line of text
Another line of text
Some more text
Field 2 contains
1
2
3
4
5
6
Field 3 contains
Code1
Code2
Code3
Code4
etc. etc. for a variable number of lines of data in each field?
What is the expected result you need in FieldAggregate? To look like:
Code: Select all
A line of text 1 Code1
Another line of text 2 Code2
Some more text 3 Code3
4 Code4
5
6
This would be quite simple, but I'm not at all sure it's what you're trying to do. Can you give a more detailed example of how you want the result?
Hi sparkout,
Thank you for answer me. I try to achieve exactly that you understand for the expected result in the "aggregate field".
I achieve to write the first line of each field to the first line of the "aggregate field", but I don't achieve the repeat loop to write the others lines of fields... I use effectively tab separation as in your example.
I think it is quite simple as you say, but I have many problems to achieve repeat loops...
Thanks for your help !
Vincent.
Thank you for answer me. I try to achieve exactly that you understand for the expected result in the "aggregate field".
I achieve to write the first line of each field to the first line of the "aggregate field", but I don't achieve the repeat loop to write the others lines of fields... I use effectively tab separation as in your example.
I think it is quite simple as you say, but I have many problems to achieve repeat loops...
Thanks for your help !
Vincent.
Hi Vincent,
See if this works:I have made this as a generic function to be able to cater for a different number of fields to aggregate. If they are all on the same card, you can use the same function to aggregate a different set of fields. Otherwise you will have to reference them a bit more, but you could get the id of the source fields beforehand and use those instead, or some similar way.
HTH
PS, I put up a sample stack in my RevOnline space for you to try - title Vincent Aggregate Stack
See if this works:
Code: Select all
on mouseUp
put fnAggregate ("fld1", "fld2", "fld3", "fld4", "fld5", "fld6") into field "fldAggregate"
--put the NAMES of the fields that you want to combine into
--one aggregate data field, in the order you want them to appear
--as columns of data in the destination field
end mouseUp
function fnAggregate
local tFldName, tParam, tColumnData, tAggregateData
set the itemDelimiter to tab
repeat with tParam = 1 to the paramCount
--as we can have a flexible amount of fields to aggregate, we
--have used this method of interrogating the parameters passed
--to the handler. The paramCount is the number of parameters
--that have been passed, so param (1) will be the first field name that
--was specified in the function call, param (2) is the second field name
--passed, and so on
put param (tParam) into tFldName
--you would need to use long names or field IDs instead of the short
--names used here if the source fields were not on the same card
put field tFldName into tColumnData
--get the contents of each field in turn, and tidy it a bit
repeat until the last line of tColumnData is not empty
delete the last line of tColumnData
end repeat
--if you are sure that no blank lines will be in any of the fields
--then you could use "filter tColumnData without empty"
--but it would close up any blank lines and if you did have any
--it would then put the data on the wrong line of the aggregate field
replace tab with "~tab~" in tColumnData
--just to make sure that any tabs in the source field do not
--affect the aggregate field, convert them so you can see them
repeat with tLine = 1 to the number of lines in tColumnData
put line tLine of tColumnData into item tParam of line tLine of tAggregateData
--actually build the aggregate data variable
end repeat
end repeat
return tAggregateData
end fnAggregate
HTH
PS, I put up a sample stack in my RevOnline space for you to try - title Vincent Aggregate Stack
In Rev in the toolbar near the right hand end (third icon from the right) you will see a RevOnline icon. If you click it you will get a "browser" for the RevOnline spaces and stacks available to anyone with a Rev license. Lots of info and shareable stacks are there.
Go to RevOnline and click "User Spaces" in the left pane and select "Browse Users", find SparkOut and see the "Vincent Aggregate Stack" - select that and click "Go To" and you will get the stack downloaded to try out. You can save it on your machine and edit it as you will.
Go to RevOnline and click "User Spaces" in the left pane and select "Browse Users", find SparkOut and see the "Vincent Aggregate Stack" - select that and click "Go To" and you will get the stack downloaded to try out. You can save it on your machine and edit it as you will.
Hi Sparkout,
thanks for revonline. I try with your proposition but I have a problem with... So, I do this:
on sauvegarder
ask file "Enregistrement fichier de données" with type ".Txt"
if ((filename is empty) or ("Cancel")) then
exit sauvegarder
else
put it into filename
open file filename
write field "fld_information_video" & return to file filename
write "Timecode" & tab & "Protagonistes" & tab & "Verbalisations" & tab & "Prédicats" & tab & "Arguments1" & tab\
& "Arguments2" & tab & "Situations" & tab & "Phases" & tab & return to file filename
------------------
put fnAggregate ("fld_donnees_timecode","fld_donnees_protagonistes","fld_donnees_verbalisations",\
"fld_donnees_predicats","fld_donnees_arguments1", "fld_donnees_arguments2","fld_donnees_situations",\
"fld_donnees_phases") into filename
close file filename
end if
end sauvegarder
function fnAggregate
local tFldName, tParam, tColumnData, tAggregateData
set the itemDelimiter to tab
repeat with tParam = 1 to the paramCount
put param (tParam) into tFldName
put field tFldName into tColumnData -- THIS LIGNE RETURN AN ERROR MESSAGE
repeat until the last line of tColumnData is not empty
delete the last line of tColumnData
end repeat
replace tab with "~tab~" in tColumnData
repeat with tLine = 1 to the number of lines in tColumnData
put line tLine of tColumnData into item tParam of line tLine of tAggregateData
end repeat
end repeat
return tAggregateData
end fnAggregate
Vincent.
thanks for revonline. I try with your proposition but I have a problem with... So, I do this:
on sauvegarder
ask file "Enregistrement fichier de données" with type ".Txt"
if ((filename is empty) or ("Cancel")) then
exit sauvegarder
else
put it into filename
open file filename
write field "fld_information_video" & return to file filename
write "Timecode" & tab & "Protagonistes" & tab & "Verbalisations" & tab & "Prédicats" & tab & "Arguments1" & tab\
& "Arguments2" & tab & "Situations" & tab & "Phases" & tab & return to file filename
------------------
put fnAggregate ("fld_donnees_timecode","fld_donnees_protagonistes","fld_donnees_verbalisations",\
"fld_donnees_predicats","fld_donnees_arguments1", "fld_donnees_arguments2","fld_donnees_situations",\
"fld_donnees_phases") into filename
close file filename
end if
end sauvegarder
function fnAggregate
local tFldName, tParam, tColumnData, tAggregateData
set the itemDelimiter to tab
repeat with tParam = 1 to the paramCount
put param (tParam) into tFldName
put field tFldName into tColumnData -- THIS LIGNE RETURN AN ERROR MESSAGE
repeat until the last line of tColumnData is not empty
delete the last line of tColumnData
end repeat
replace tab with "~tab~" in tColumnData
repeat with tLine = 1 to the number of lines in tColumnData
put line tLine of tColumnData into item tParam of line tLine of tAggregateData
end repeat
end repeat
return tAggregateData
end fnAggregate
Vincent.
Bonsoir Vincent
Where exactly are the fields in relation to the handler and function that it calls? Are they on the same card? If you try with the RevOnline stack you should see that it works in principle. If you need to source the data from any particular field on another card or stack, you will need to reference it differently - by using its long name as the parameter, or adjusting the function to use field ID numbers, for example.
If and when the error issue is resolved, I notice that when you call the function, you return the result into the variable filename - which is presumably not what you want. You will need to write the returned data to file filename, I think.
HTH
Where exactly are the fields in relation to the handler and function that it calls? Are they on the same card? If you try with the RevOnline stack you should see that it works in principle. If you need to source the data from any particular field on another card or stack, you will need to reference it differently - by using its long name as the parameter, or adjusting the function to use field ID numbers, for example.
If and when the error issue is resolved, I notice that when you call the function, you return the result into the variable filename - which is presumably not what you want. You will need to write the returned data to file filename, I think.
HTH