Assigning one array[] to another[]
in
Programming Questions
•
1 year ago
HI,
first post so go easy on me
.
i have only been using processing for about a week now and have come unstuck.
i`m having an issue with this code i wrote, it works but i get NULL values in my results.csv file.
i will post all of the code but there is a stock report and location check .csv files missing.
i believe the the line in red is my failing but do not know how to fix it.
import javax.swing.*;
int records;
int records1;
int count;
int x;
int y = 80;
int i=0;
int j=0;
int position=0;
int a;
int pos;
int findme =0;
int ff = 20;
int xx = 100;
String[] stocklist;
String[] location;
String[] txt = split("Barcode,Item,Location,Size,Description,Qty,Pick,Putaway,Available,Default,Fixed,XDoc",',');
String search;
String[] savtxt;
int index = 0;
void setup() {
size(1000, 800);
background(0);
smooth();
PFont font;
font = loadFont("Mine.vlw");
textFont(font);
textSize(18);
// create a file chooser
final JFileChooser fc1 = new JFileChooser();
// in response to a button click:
int returnVal1 = fc1.showOpenDialog(this);
if (returnVal1 == JFileChooser.APPROVE_OPTION) {
File file1 = fc1.getSelectedFile();
stocklist = loadStrings(file1); // load text file into stocklist[] array
}
else {
println("Open command cancelled by user.");
}
// create a file chooser
final JFileChooser fc2 = new JFileChooser();
// in response to a button click:
int returnVal2 = fc2.showOpenDialog(this);
if (returnVal2 == JFileChooser.APPROVE_OPTION) {
File file2 = fc2.getSelectedFile();
location = loadStrings(file2); // load text file into [] array
}
else {
println("Open command cancelled by user.");
}
records = (stocklist.length); // length of text file
records1 = (location.length); // length of text file
}
void draw() {
stroke(0);
fill(0);
rect(0, 0, width, 100); // clear top area for text display
fill(255);
search = location[findme];
String[] pieces = split(stocklist[j], ','); // split stocklist[] array into pieces[] array using tab delimit `,`
String[] savtxt = new String[records1];
x=20;
for (int i = 0; i < 9; i = i+1) {
text(pieces[i], x, y); //print pieces[] array
String str = pieces[i];
int index = str.indexOf(search);
pos=60;
if (i==0) {
pos=100;}
if (i==1) {
pos=100;}
if (i==2) {
pos=120;}
if (i==3) {
pos=100;}
if (i==4) {
pos=320;}
x=x+pos;
fill(0);// clear for update text display
rect(0, 0, width, 50); // clear for update text display
fill(255); // clear for update text display
text("Index "+(j+1), 20, 20);text("of Records "+records, 120, 20);
text("Looking For "+search, 450, 20);text("in Array "+findme, 700, 20);
if (index == -1){}
else{
text(" Found in "+txt[i]+" of "+"Record "+(j)+" "+stocklist[j], 20, xx+ff);ff = ff + 20;
savtxt[position] = stocklist[j];
//arrayCopy(stocklist, j, savtxt, position, 1);
j=0;
position=position+1;
findme = findme +1;
}
}
//delay(20);
text(""+savtxt[position], 450, 40);
j=j+1;
if (j==records) {
j=0;
text("ERROR NOT FOUND", width/2, height/2);
findme = findme +1;}
if (findme == records1-1) {
fill(255,0,0);
textSize(30);
text("Finished With Success", width/2, height/2);
saveStrings("RESULTS.csv", savtxt);
}
}
first post so go easy on me

i have only been using processing for about a week now and have come unstuck.
i`m having an issue with this code i wrote, it works but i get NULL values in my results.csv file.
i will post all of the code but there is a stock report and location check .csv files missing.
i believe the the line in red is my failing but do not know how to fix it.
import javax.swing.*;
int records;
int records1;
int count;
int x;
int y = 80;
int i=0;
int j=0;
int position=0;
int a;
int pos;
int findme =0;
int ff = 20;
int xx = 100;
String[] stocklist;
String[] location;
String[] txt = split("Barcode,Item,Location,Size,Description,Qty,Pick,Putaway,Available,Default,Fixed,XDoc",',');
String search;
String[] savtxt;
int index = 0;
void setup() {
size(1000, 800);
background(0);
smooth();
PFont font;
font = loadFont("Mine.vlw");
textFont(font);
textSize(18);
// create a file chooser
final JFileChooser fc1 = new JFileChooser();
// in response to a button click:
int returnVal1 = fc1.showOpenDialog(this);
if (returnVal1 == JFileChooser.APPROVE_OPTION) {
File file1 = fc1.getSelectedFile();
stocklist = loadStrings(file1); // load text file into stocklist[] array
}
else {
println("Open command cancelled by user.");
}
// create a file chooser
final JFileChooser fc2 = new JFileChooser();
// in response to a button click:
int returnVal2 = fc2.showOpenDialog(this);
if (returnVal2 == JFileChooser.APPROVE_OPTION) {
File file2 = fc2.getSelectedFile();
location = loadStrings(file2); // load text file into [] array
}
else {
println("Open command cancelled by user.");
}
records = (stocklist.length); // length of text file
records1 = (location.length); // length of text file
}
void draw() {
stroke(0);
fill(0);
rect(0, 0, width, 100); // clear top area for text display
fill(255);
search = location[findme];
String[] pieces = split(stocklist[j], ','); // split stocklist[] array into pieces[] array using tab delimit `,`
String[] savtxt = new String[records1];
x=20;
for (int i = 0; i < 9; i = i+1) {
text(pieces[i], x, y); //print pieces[] array
String str = pieces[i];
int index = str.indexOf(search);
pos=60;
if (i==0) {
pos=100;}
if (i==1) {
pos=100;}
if (i==2) {
pos=120;}
if (i==3) {
pos=100;}
if (i==4) {
pos=320;}
x=x+pos;
fill(0);// clear for update text display
rect(0, 0, width, 50); // clear for update text display
fill(255); // clear for update text display
text("Index "+(j+1), 20, 20);text("of Records "+records, 120, 20);
text("Looking For "+search, 450, 20);text("in Array "+findme, 700, 20);
if (index == -1){}
else{
text(" Found in "+txt[i]+" of "+"Record "+(j)+" "+stocklist[j], 20, xx+ff);ff = ff + 20;
savtxt[position] = stocklist[j];
//arrayCopy(stocklist, j, savtxt, position, 1);
j=0;
position=position+1;
findme = findme +1;
}
}
//delay(20);
text(""+savtxt[position], 450, 40);
j=j+1;
if (j==records) {
j=0;
text("ERROR NOT FOUND", width/2, height/2);
findme = findme +1;}
if (findme == records1-1) {
fill(255,0,0);
textSize(30);
text("Finished With Success", width/2, height/2);
saveStrings("RESULTS.csv", savtxt);
}
}
1