Simple While loop problem
Hi have a simple while loop and I don't know what's wrong, I want the contents of the Line variable spilt by commas to be placed in a structure.
The loop never stops, If I clear the contents of the Line variable in debug then the loop stops and the structure is populated.
Line = ",105,103,125,117,102,116,126,113,112,119,108,109,110,118"
WHILE(LENGTH_STRING(Line) > 2){
Sources.ButtonNo[count] = ATOI(REMOVE_STRING(Line, ',', 1))
count=count+1
}
The loop never stops, If I clear the contents of the Line variable in debug then the loop stops and the structure is populated.
0
Comments
Another thing to bear in mind is that when you hit the last number, there is no longer a comma to remove. So "Line" will be stuck at 3 chars long. You might want to put the whole evaluation inside an if(find_string(Line,',',1)) statement. That way when you're on the last number you'll know because the find_string:comma will fail. you could do something like this:
if(find_stirng(Line,',',1){ Sources.ButtonNo[count] = ATOI(REMOVE_STRING(Line, ',', 1)) count=count+1 } // if find_string else if(length_string(Line))){ // last char Sources.ButtonNo[count] = ATOI(Line); Line='' /// clear out last number - making Line length zero and killing the loop }// elseThank you.
WHILE(LENGTH_STRING(SOURCESDATA > 0)){ Line = REMOVE_STRING(SOURCESDATA, CRLF, 1) If(FIND_STRING(Line, 'Obs Cabin2' , 1)){ count=1 WHILE(LENGTH_STRING(Line) > 0){ If(FIND_STRING(Line, ',' , 1)){ Sources.Enable[count] = ATOI(REMOVE_STRING(Line, ',', 1)) count=count+1 }Else{ // last char Sources.Enable[count] = ATOI(Line); Line='' /// clear out last number - making Line length zero and killing the loop } } Break } }The function REMOVE_STRING() is not the problem here. Your *logic* is the culprit.
Line 1:
WHILE(LENGTH_STRING(SOURCESDATA > 0)){evaluates to TRUE if anything is in SOURCEDATALine 3:
If(FIND_STRING(Line, 'Obs Cabin2' , 1)){evaluates to TRUE if Obs Cabin2 exists in the Line variable.Why should a FALSE for Line 3 automatically assume Line 1 is FALSE? They have nothing to do with each other.
Hi, Line 2 should be removing one line at a time from SOURCESDATA, when all lines have gone then line 1 should return FALSE.
Thanks....