Index and length must refer to a location within the string.
youngdave
Posts: 70
Dear All
I often get the following annoying error with the code (in ViewPort) below. Sometimes the code works fine, and sometimes I get this error.
What am I doing wrong?
Index and length must refer to a location within the string.
Parameter name: length
Debugger USER INTERFACE
The code is as follows:
=PUB Cull_excess_population | n
=
= repeat while Current_Population_Size > max_population_size
= n := || rr.random // Current_Population_Size + 1
= repeat while n < Current_Population_Size
= Chromosome[noparse][[/noparse]n] := Chromosome[noparse][[/noparse]n+1]
= n++
= Current_Population_Size --
TIA David Young
I often get the following annoying error with the code (in ViewPort) below. Sometimes the code works fine, and sometimes I get this error.
What am I doing wrong?
Index and length must refer to a location within the string.
Parameter name: length
Debugger USER INTERFACE
The code is as follows:
=PUB Cull_excess_population | n
=
= repeat while Current_Population_Size > max_population_size
= n := || rr.random // Current_Population_Size + 1
= repeat while n < Current_Population_Size
= Chromosome[noparse][[/noparse]n] := Chromosome[noparse][[/noparse]n+1]
= n++
= Current_Population_Size --
TIA David Young
Comments
You've really got to start posting your programs between [noparse][[/noparse]code] and [noparse][[/noparse]/code] tags, at the very least; or use the code formatter at www.phipi.com/format. Without doing so, your indentations disappear.
-Phil
tags ................
Not everyone knows what you're talking about! Can't be too hard to give an example can it?
TIA David Young
If it's still too confusing, just read the forum help page here: forums.parallax.com/forums/help.aspx. Look under the mcode reference at Code.
-Phil
Hope the formatting's OK.
I often get the following annoying error with the code (in ViewPort) below. Sometimes the code works fine, and sometimes I get this error.
What am I doing wrong?
Index and length must refer to a location within the string.
Parameter name: length
Debugger USER INTERFACE
The code is as follows:
I'm not familiar with ViewPort, but it looks from your code that you're assuming that array indexing is 1-based. In Spin, arrays begin with subscript 0. So I think what you want is this:
Also, you can save a lot of compute time if you use longmove (assuming your chromosomes are longs), instead of the repeat loop.
-Phil
Thanks. I'll work on that.
TIA David Young