We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello I'm trying to make a program which calculates values which it gets from a spreadsheet. I'm using a ControlP5 scrollable list to show all the possible selection. Each item in the list represents a row in the spreadsheet. To each row there is 7 columns.
So my question is how do i let processing know or rather code, that the item selected in the list is a row in the spreadsheet? It's very poorly explained i know, but i will try to explain further if need! Thank you so much in advance!
A simplified version of my code:
`
import controlP5.*;
import java.util.*;
ControlP5 cp5;
ScrollableList initialBodyList;
Button butDeltaVplanet;
Table Planeter;
Textfield required_delta_V;
void setup() {
size(500, 500);
cp5 = new ControlP5(this);
Planeter = loadTable("DatasheetPlanets.csv", "header");
butDeltaVplanet = cp5.addButton("Calculate required Delta V")
.setPosition(300, 50)
.setColorForeground(#EA0037)
.setColorActive(#FF4343)
.setSize(130, 30);
List body = Arrays.asList("Kerbol", "Moho", "Eve", " Gilly", "Kerbin", " Mun", " Minmus", "Duna", " Ike", "Dres", "Jool", " Laythe", " Vall", " Tylo", " Bop", " Pol", "Eeloo");
initialBodyList = cp5.addScrollableList("Initial body")
.setPosition(70, 50)
.setSize(200, 300)
.setBarHeight(30)
.setItemHeight(20)
.setBackgroundColor(#EA0037)
.setColorForeground(#EA0037)
.setColorActive(#FF4343)
.addItems(body)
.setOpen(false);
required_delta_V = cp5.addTextfield("Required Delta V m/s")
.setPosition(300, 120)
.setSize(130, 30);
ControlP5.printPublicMethodsFor(Textfield.class);
}
void draw() {
background(200);
}
public void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom(butDeltaVplanet)) {
int planet1 = Planeter.getRow(3).getInt("DeltaVtoKerbinorbit");
int planet2 = Planeter.getRow(4).getInt("DeltaVtoKerbinorbit");
float deltaV = 0;
deltaV = planet1 + planet2;
required_delta_V.setText(" " + deltaV);
}
}`
Answers
Edit post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below....
Kf
Thanks! Having a hard time figureing out how the forum works ;)
Will each scrollable list item represent a row of your spreadsheet or are you doing a calculation on the dta in each row and loading it in the spreadsheet?
https://forum.processing.org/two/search?Page=p2&Search=spreadsheet
Kf
I solved it on my own, but thank you for answering!