Fill pulldown with CSV file header
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Fill pulldown with CSV file header
I'm trying to read the header of a CSV file and put "it" into a pulldown list (i.e., menu) which will allow me to select a column of data to be used as the 'Y' axis chart data with the 'X' axis always being the first column.
The number of columns of data and names of each column could be different for each file.
I have succeeded at filling the button with the header row text but this obviously is not what I need to do to make each item selectable.
Thanks!
The number of columns of data and names of each column could be different for each file.
I have succeeded at filling the button with the header row text but this obviously is not what I need to do to make each item selectable.
Thanks!
If you mean that your menu options now look correct but they're not selectable then it sounds like you've done it all really, bar handling the menuPick message.
By default when you drag out a pulldown menu button, its script will be set to:for you to fill in what action to take according to the selection. The pItemName parameter will be whichever menu item was selected so you could do something like:You needn't necessarily handle different options in the switch/case block. It's possible you just need to pass the selected option to your chart drawing routine:or simplydepending on how you call it/set it.
If you're still having trouble with getting the right values in the right places to be selected, then perhaps you can post a sample of what you've done to be able to get a better idea of what you need to do.
By default when you drag out a pulldown menu button, its script will be set to:
Code: Select all
on menuPick pItemName
switch pItemName
end switch
end menuPick
Code: Select all
on menuPick pItemName
switch pItemName
case "cat"
answer "You selected the 'cat' menu option"
break
case "dog"
answer "You selected the 'dog' menu option"
break
case "gnu"
case "wildebeest"
answer "You selected the 'gnu' menu option (it's the same as a wildebeest, you know)"
break
default
answer "You selected a menu option that wasn't 'cat' or 'dog' or 'gnu' (or 'wildebeest')"
end switch
end menuPick
Code: Select all
on menuPick pItemName
set the uAxisColumn of group "ChartArea" to pItemName
drawChart
end menuPick
Code: Select all
on menuPick pItemName
drawChart pItemName
end menuPick
If you're still having trouble with getting the right values in the right places to be selected, then perhaps you can post a sample of what you've done to be able to get a better idea of what you need to do.
Thanks for the input SparkOut. Unfortunately, when I stated that I had succeeded at filling the menu I was not clear (not even truly accurate). I filled the menu with the header row of my file but the entire row is "put" as one item.
I was thinking of attempting a switch/case method (as you described) but I'm not sure how to fill the menu list from the data file so that selectable items are created.
thnx
I was thinking of attempting a switch/case method (as you described) but I'm not sure how to fill the menu list from the data file so that selectable items are created.
thnx
-
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
- Contact:
most likely your csv data is delimited by something else then return. the menubuttons of rev always want return delimited lists. The following script assumes your data is delimited by tabulator (tab):
Code: Select all
on mouseUp
answer file "a csv file please"
if it = "" or the result = "cancel" then
exit mouseUp
end if
put it into theFilepath
put url ("file:" & theFilepath) into theData
put line 1 of theData into theHeaders
replace tab with return in theHeaders --dropdown wants return delimited list
put theHeaders into button "someDropdown"
end mouseUp
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode