Fill pulldown with CSV file header

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!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
t-rex22
Posts: 20
Joined: Tue Mar 31, 2009 3:56 pm
Location: Michigan, USA

Fill pulldown with CSV file header

Post by t-rex22 » Mon Aug 24, 2009 11:36 am

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!

SparkOut
Posts: 2328
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Mon Aug 24, 2009 12:27 pm

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:

Code: Select all

on menuPick pItemName
   switch pItemName
      
   end switch
end menuPick
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:

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
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:

Code: Select all

on menuPick pItemName
  set the uAxisColumn of group "ChartArea" to pItemName
  drawChart
end menuPick
or simply

Code: Select all

on menuPick pItemName
  drawChart pItemName
end menuPick
depending 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.

t-rex22
Posts: 20
Joined: Tue Mar 31, 2009 3:56 pm
Location: Michigan, USA

Post by t-rex22 » Mon Aug 24, 2009 1:12 pm

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

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Mon Aug 24, 2009 1:41 pm

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

t-rex22
Posts: 20
Joined: Tue Mar 31, 2009 3:56 pm
Location: Michigan, USA

Post by t-rex22 » Mon Aug 24, 2009 2:43 pm

Yes! Thanks BvG, replacing the comma delimiter with a return works for loading the menu items.

Now, I have to figure out how to make the selection(s) use the desired column(s) of data.

thnx!!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”