Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Tip - _ in VB Procedure Names

Tip - _ in VB Procedure Names

Tip - _ in VB Procedure Names

from microsoft's web site

Visual Basic: Avoid Using Underscore in Procedure Names
December 6, 1999

In Visual Basic, "underscore" ('_') is allowed in a variable, sub, function or property name. In fact, some schools of thought advise using underscores in code to make the code more readable and easier to maintain.

However, in Visual Basic there is a special case where '_' cannot be used in a sub, property or function case. When you are defining an interface (abstract class), Visual Basic doesn't warn you against using the '_' in the procedure, sub or function name. But when you try to implement this interface in a class module, your code won't compile.

To see this in action, define class modules A and B as follows:

Class A:

public property get Prop_A() as variant
end property

public property let Prop_A(pa as variant)
end property

Class B:

Implements A

private property get A_Prop_A() as variant
'.... implement the property
end property

private property Let A_Prop_A(pa as variant)
'....implement the property
end property
When you try to compile the project, you will get the following error:

Compile error:
Object module needs to implement 'Prop_A' for interface 'A'
To work around this problem, change the name of the property in class module A from Prop_A to one that doesn't include the '_'; for example, PropA.

This article was written by Hemant Attray.

Mike Lacey
Cargill's Corporate Web Site

RE: Tip - _ in VB Procedure Names

Nice tip as always Mike!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close