dcsimg
Results 1 to 8 of 8

Thread: Compiler Errors

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    3

    Question 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..?

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,579

    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    PowerPoster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,138

    Re: Compiler Errors

    Quote Originally Posted by Ramesh G View Post
    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!

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,579

    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    539

    Re: Compiler Errors

    Quote Originally Posted by Elroy
    Compile On Demand
    How exactly this option change behavior?

    Quote Originally Posted by Ramesh G View Post
    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.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,579

    Re: Compiler Errors

    Quote Originally Posted by Dragokas View Post
    Quote Originally Posted by Elroy View Post
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  7. #7
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    539

    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.

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,579

    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. 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
  •  



Featured


Click Here to Expand Forum to Full Width