Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tip - _ in VB Procedure Names

Status
Not open for further replies.

MikeLacey

MIS
Nov 9, 1998
13,212
GB
from microsoft's web site<br>
<br>
Visual Basic: Avoid Using Underscore in Procedure Names<br>
December 6, 1999<br>
<br>
<br>
<br>
In Visual Basic, &quot;underscore&quot; ('_') 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.<br>
<br>
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.<br>
<br>
To see this in action, define class modules A and B as follows:<br>
<br>
Class A:<br>
<br>
public property get Prop_A() as variant<br>
end property<br>
<br>
public property let Prop_A(pa as variant)<br>
end property<br>
<br>
<br>
Class B:<br>
<br>
Implements A<br>
<br>
private property get A_Prop_A() as variant<br>
'.... implement the property<br>
...<br>
end property<br>
<br>
private property Let A_Prop_A(pa as variant)<br>
'....implement the property<br>
...<br>
end property<br>
When you try to compile the project, you will get the following error:<br>
<br>
Compile error:<br>
Object module needs to implement 'Prop_A' for interface 'A'<br>
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.<br>
<br>
This article was written by Hemant Attray.<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Nice tip as always Mike!<br>
<br>
-Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top