Page 1 of 1
Pulldown text selection to select column in CSV file
Posted: Thu Aug 27, 2009 8:36 pm
by t-rex22
I am placing the header row from a CSV file into a pulldown button. I want to have the user selection ("ColumnValue") in the pulldown set the column to be plotted.
Code: Select all
repeat for each line aLine in tFileData
put item 1 of aLine & comma & ColumnValue & return after tChartData
end repeat
The button appears to be working but the information passed from the button is a text string and the "put" command needs a numeric column value.
Is there a "lookup" type command I can use to find the pulldown selection in the header row and thus pass the column number?
Thanks!
Posted: Thu Aug 27, 2009 8:52 pm
by bn
Hi t-rex22,
could you give a short example of your data in its original form including the headers and an example of what the output should look like, I am afraid I dont quite understand.
regards
Bernd
Posted: Thu Aug 27, 2009 10:35 pm
by SparkOut
I could do with a bit more info to, but are your column headers numbers? Or do you want to have say a list of options like:
Sheep
Cattle
Pigs
Horses
Wildebeest
and get the value 1 for Sheep, 2 for Cattle, and so on? In which case that could maybe be as simple as:
Code: Select all
on menuPick pItemName
drawChart lineOffset (pItemName,the text of me)
end menuPick
If the list of names is the same order as the columns then this should work - you could always add an offset value if the first option was the fourth column, etc.
Posted: Thu Aug 27, 2009 11:29 pm
by t-rex22
A rough sample of my data is:
Time,Velocity,ProbeAccel
ms,m/s,m/s^2
-1.00000,1.00000,-4.56789
...
I have so far succeeded at filling the pulldown menu with the header row (row 1) but I have not yet figured out how to allow the user to pick one of the options (Velocity or ProbeAccel) and have "it" plotted against "Time".
The plotting routine (chartsengine) will plot whichever column I "hard" write into the line I showed in my first post.
Is that any clearer?
Posted: Thu Aug 27, 2009 11:59 pm
by bn
t-rex22,
try this:
Code: Select all
on menuPick pItemName
-- assuming you have the header in the menu
-- assuming tFileData has no header, just the data
-- if time is in the menu you obviously would not want to plot time against time
-- you either take time out of the menu or you can catch this
-- if pItemName = "time" then exit menuPick -- unblock this line if you leave time in the menu
put lineOffset(pItemName,the text of me) into tLineNo
repeat for each line aLine in tFileData
put item 1 of aLine & comma & item tLineNo of aLine & return after tChartData -- with time in the menu
-- put item 1 of aLine & comma & item tLineNo + 1 of aLine & return after tChartData -- unblock this if you take time out of the menu
end repeat
delete last char of tChartData -- return
-- puts the data into the message box
put tChartData --into field "f2"
end menuPick
it is as sparkout suggested, you determine the line number which is the item number to look for.
In case you dont want time in the menu you have to add 1 to the line number (look at the comments in the code)
I hope I got you right.
regards
Bernd
Posted: Fri Aug 28, 2009 10:17 am
by t-rex22
That worked, thank you very much!!!