We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Error message (Read 758 times)
Error message
Nov 4th, 2009, 3:56pm
 
I want to play about with text sourced from online, but I keep getting the error 'cant find anything named 'i' ' - I dont think I've had to initialize i in a for loop before..? What have I done wrong here please?

Code:


String textLines [] = loadStrings("webpage text (cannot post as am new to the forum)");

String textLinesJoined = join(textLines, " ");

int start = textLinesJoined.indexOf("Edna Lumb was a student");
int end = textLinesJoined.indexOf(".", start);
String selectedText = textLinesJoined.substring(start, end);

for(i=0; i < selectedText.length; i++) {
char letter = a;
if(selectedText.charAt(2) == letter) {
 fill(100, 0, 0);
}
}

println(selectedText);

Re: Error message
Reply #1 - Nov 5th, 2009, 1:37am
 
first you are missint the INT in int i  = 0;
second problem you have to write 'a' not only a...

still not working though as i cant test it without the website, file you load.
Re: Error message
Reply #2 - Nov 5th, 2009, 3:53am
 
Many thanks!
Re: Error message
Reply #3 - Nov 5th, 2009, 5:27am
 
Well I've changed it about so it looks a bit better I think, but the value of 'int a' which i am using to count the repetitions of the character 'a' only updates once for some reason.

(web address contains spaces).

Code:


String textLines [] = loadStrings("ht tp:// ww w. leeds. g ov. uk /");

String textLinesJoined = join(textLines, " ");

int start = textLinesJoined.indexOf("Get the very");
int end = textLinesJoined.indexOf(".", start);
String selectedText = textLinesJoined.substring(start, end);

void draw() {

for(int i=0; i < selectedText.length(); i++) {
char letter = 'a';
int b = 10;
if(selectedText.charAt(i) == letter) {
  int a = b + 20;
   println(a);

   fill(100, 0, 0);
 ellipse (a, a, 20, 20);

}


}

println(selectedText);
}

Re: Error message
Reply #4 - Nov 5th, 2009, 6:07am
 
You define the a variable within the if () {} block. The variable (and its value) is forgotten as soon as you quit this block (on next loop), so you draw all your circles on the same place.
Beside, you should define your constants outside of the loop.
Re: Error message
Reply #5 - Nov 5th, 2009, 6:54am
 
Yes that has worked thankyou both.
Page Index Toggle Pages: 1