Results 1 to 8 of 8

Thread: Compiler Errors

Hybrid View

  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
    9,936

    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.

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,836

    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
    9,936

    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.

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

    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.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

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

    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. To all, peace and happiness.

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

    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.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

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

    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
  •  



Click Here to Expand Forum to Full Width