Pulldown text selection to select column in CSV file

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: FourthWorld, heatherlaine, Klaus, kevinmiller

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

Pulldown text selection to select column in CSV file

Post by t-rex22 » Thu Aug 27, 2009 8:36 pm

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!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Thu Aug 27, 2009 8:52 pm

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

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

Post by SparkOut » Thu Aug 27, 2009 10:35 pm

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.

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

Post by t-rex22 » Thu Aug 27, 2009 11:29 pm

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?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Thu Aug 27, 2009 11:59 pm

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

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

Post by t-rex22 » Fri Aug 28, 2009 10:17 am

That worked, thank you very much!!!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”