For y as integer = 0 to batchlist(batchID).encodefilterObjects.ubound
line = line + "<key>Audio1"+str(y)+" "+str(batchlist(batchID).encodefilterObjects(y).audio1)+"</key>"+chr(13)
line = line + " <false></false>"+chr(13)
.... (about 100 lines in this for-next loop)
next y
-> this gives a compiler error.
This method is too long
End Function
When I replace the for-nextloop with a while-wend loop it is working fine.
Dim y as integer = 0
while y-1 < batchlist(batchID).encodefilterObjects.ubound
line = line + "<key>Audio1"+str(y)+" "+str(batchlist(batchID).encodefilterObjects(y).audio1)+"</key>"+chr(13)
line = line + " <false></false>"+chr(13)
.... (about 100 lines in this for-next loop)
y = y +1
Wend
I have the same method but now for loading the saved settings from the above method.
That method has the SAME amount of code lines and does not give the error.
The troubling methode is just using 3 local variables.
One of the local variable just add text to a string variable. Nothing more nothing less. I would say about 100 lines, so that isn’t much either.
And why does it work when I put the same code between while-wend loop?
Did a quick test:
Got the error in both 2014r2.1 and 2014r3a9
Another test:
When I remove some lines so the for-next loop only has about 80 lines the compiler does not complain.
To be clear:
The For-next loop only has code like this:
line = line + “Audio1”+str(y)+" “+str(batchlist(batchID).encodefilterObjects(y).audio1)+”"+chr(13)
line = line + " "+chr(13)
batchlist(batchID).encodefilterObjects(y).audio1 is an integer and mostly between 1 or 5 chars long.
So in the end the line.len would be between 100 and 500. Nothing special I guess.
It seems it doesn’t have to do anything with methods at all.
There is a limit in code lines between for-next loops which is just crazy imo
On first tests a max. of 375 lines is allowed.
Now isn’t that very strange?
To reproduce:
Add the below code in the Open event of a window:
[code]Dim text as string
for a as integer = 0 to 100
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
text = text + “This is a test”+chr(13)
… copy/paste the text = text + “This is a test”+chr(13) a couple of times
text = text + "This is a test"+chr(13)
text = text + "This is a test"+chr(13)
text = text + "This is a test"+chr(13)
next a
[/code]
This will give an error:
This method is too long
End Sub
Putting the same code between do-loop or while-wend works fine.
[quote=122670:@Christoph De Vocht]line = line + “Audio1”+str(y)+" “+str(batchlist(batchID).encodefilterObjects(y).audio1)+”"+chr(13)
line = line + " "+chr(13)[/quote]
You can probably save a lot of temporary variables shuffle with continued lines such as :
[code]line = line + “Audio1”+str(y)+" “+str(batchlist(batchID).encodefilterObjects(y).audio1)+”"+chr(13) _
" "+chr(13)[/code]
Each time you go line = line+, I believe that creates in effect two temporary variables on top of the original line to hold the result, and the concatenating one. If for some reason the stack is not releasing them right away, it can probably fill it up real quick.
In terms of code formatting, a continued line will probably not shatter too much the presentation, and may save you some extra memory.
[quote=122680:@Christoph De Vocht]There is a limit in code lines between for-next loops which is just crazy imo
On first tests a max. of 375 lines is allowed.[/quote]
This is nonsense. I have for-next loops in my apps with way more than 1000 lines in between.
You should - as Norman has indicated - refactor your code to not create as many temporary variables as now.
Create functions for building parts of the final string. I assume you are creating a plist-like string. Then you could create methods like:
Function CreateBooleanEntry(key As String, value As Boolean) As String
Function CreateIntegerEntry(key As String, value As Integer) As String
...
[quote=122683:@Christoph De Vocht]Yes, that would help for sure. But still … it is a strange issue.
It also does not explain why it works in other loops like do-loop and while-wend. :-)[/quote]
Norman suggested it is a memory issue, and I will trust his expertise.
I am not a system designer, but I would believe a while-wend or do-loop require less memory than a for next since they only verify a condition as opposed to keep a counter. But without being your code, I cannot help to wonder if having so many lines in a method does not indicate a need for breaking it in smaller methods. The advantage of a separate method is also that it releases memory after termination.
I referred explicitly to the following conclusion you made - which is nonsense - not to your example:[quote]Christoph De Vocht There is a limit in code lines between for-next loops which is just crazy imo. On first tests a max. of 375 lines is allowed.[/quote]
I also gave an example how you could reduce the memory foot print by splitting your sting generation into smaller parts.