-
Mar 12th, 2018, 11:35 PM
#1
Thread Starter
New Member
Compiler Errors
While running codes sometimes we come across compiler error
Label not defined, sub functions not defined.
Are there any rules we need to keep in mind while defining procedures and functions..?
-
Mar 13th, 2018, 12:38 AM
#2
Re: Compiler Errors
The only rule (or really, just a suggestion) is to always explicitly type them. What I mean is to be sure and say As Boolean or As Double or As Long, etcetera. If you don't explicitly type them, the default type will be As Variant. Variants are useful for certain things, but they're an intermediate topic, and you're still learning the basics.
I suppose another suggestion would be to not be afraid to use long names for them. This will help you to remember what they're for when you come back in six months to look at the code again. Personally, I like camel-case. That's like this: ThisIsMyFunctionName. But others have different schemes as well. The underscore is also sometimes used, like this: This_Is_My_Function_Name.
It's great to see you pressing forward.
Best Of Luck,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 13th, 2018, 05:19 AM
#3
Re: Compiler Errors
Originally Posted by Ramesh G
While running codes sometimes we come across compiler error
Label not defined, sub functions not defined.
Are there any rules we need to keep in mind while defining procedures and functions..?
Always have "Option Explicit" at the top of each program. When you run the program in IDE always start with "Run with full compile". Both of those options will help with that stuff.
Please remember next time...elections matter!
-
Mar 13th, 2018, 10:36 AM
#4
Re: Compiler Errors
@TysonLPrice: I believe Ramesh is actually programming in one of the Office VBA areas. I just didn't have the heart to report him and have the thread moved, knowing this VB6 forum has quite a bit more traffic.
@Ramesh: Yes, the "Option Explicit" is excellent, basically mandatory, advice. Also, and you've probably already discovered this, but it's always advisable to execute "Compile Project" under "Debug", before actually executing your VBA project. Also, under Tools/Options/General, you'll see a "Compile On Demand" option. It's probably advisable to make sure that's turned OFF. That will further help you to find your syntax errors.
Good Luck,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 13th, 2018, 03:16 PM
#5
Re: Compiler Errors
Originally Posted by Elroy
Compile On Demand
How exactly this option change behavior?
Originally Posted by Ramesh G
Label not defined, sub functions not defined.
These mean you have not added required label (or form with a labels), which is distributed with the code or instruction to it.
"functions not defined" can be due to the absence of required dll, which you maybe should connect to the project by Tools (Project) -> References (or Components) according to that instruction.
Or you placed Function/Procedure in the wrong module, like if some procedure declared with "Public" keyword and used in another module (form or class), in such case you must place that code in common module (not a form or class).
Last edited by Dragokas; Mar 13th, 2018 at 03:24 PM.
-
Mar 13th, 2018, 03:44 PM
#6
Re: Compiler Errors
Originally Posted by Dragokas
Originally Posted by Elroy
Compile On Demand
How exactly this option change behavior?
In both VB6 and VBA, when you execute/run in the IDE (either VB6 or VBA), if it's a large project with many modules, you can have syntax errors in some modules and it'll still let you execute when this "Compile On Demand" flag is on. This really harks back to Windows 95 days when the machines were much slower. It could take a while to compile everything before executing.
However, with contemporary machines, there's little difference in speed with this flag being on or off. Therefore, it's best to turn it off. That way, all the syntax is checked (via p-code compiling) before anything is executed.
Best Regards,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Mar 13th, 2018, 03:53 PM
#7
Re: Compiler Errors
Ok, understood. In such cases i'm pressing Ctrl + F5. However, for VBA there is no such key combination, so sounds like removing "Compile On Demand" checkbox is the only option there.
-
Mar 13th, 2018, 04:33 PM
#8
Re: Compiler Errors
Yep. Same thing. In fact, in VB6, I'm fairly certain that F5 and Ctrl+F5 will do exactly the same thing if "Compile On Demand" is off.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|