'Function' can only appear in the main program
BlitzPlus Forums/BlitzPlus Beginners Area/'Function' can only appear in the main program
| ||
Has anyone else seen this error when trying to run some code? 'Function' can only appear in the main program My code was working fine, then I added more code to it and it won't run at all now giving me this unhelpful error message |
| ||
It means the compiler is seeing a function definition within some other block construct (type, If/EndIf, another function, etc). If you have a really large main loop, check that you didn't inadvertently define a function within it when part of the loop was offscreen or something? |
| ||
You probably began a block but forgot to end it. Example:For n = 1 To 5 Function nothing() End FunctionThe missing Next is the real error but the message is misleading. The function definition seems to be inside a For/Next loop. The compiler has seen For and thinks it is inside the loop until it sees Next, which it never does. |
| ||
Good call Floyd, I remember seeing this before now you mention it. The message is a bit misleading, I was looking for a bug inside my function... Sure enough, a two minute scan of my code reveals a missing Next. I spent over two fruitless hours looking for bug elsewhere. On the plus side I tidied up my code a lot, it had gotten a bit sloppy. Watch out for my game: One Million 2-Minute Puzzles coming soon!!! |