Solved

Thoughts on "proper" coding

Posted on 2004-10-12
4
131 Views
Last Modified: 2010-05-02
Potentially part 1.
I'm curious what you guys do in 'the real world'.

When you code, do you skip object properties when you're using the default?

For instance:

txtData="My text"

or

txtData.Text = "My text"

I know it's 6 one way and a 1/2 dozen the other - just looking for what the general consensus is...
0
Comment
Question by:sirbounty
4 Comments
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 25 total points
ID: 12288392
I, personally, never rely on the default properties.  txtData.Text is correct.  In recent updates to the language (VB.NET, for example), default properties no longer exist.  It's also harder to understand, for anyone re-reading your code; referring to txtData suggests you mean the control itself as in:

    Set a = txtData
    a.Text = "My Text"

says 'when I say a, I mean txtData', whereas

    a = txtData.Text

says 'put the text in txtData into a variable called a'.

Just my two cents...

HTH

J.
0
 
LVL 6

Assisted Solution

by:bkthompson2112
bkthompson2112 earned 25 total points
ID: 12288397
I always use the properties.  IMO, the code is more readable and maintainable.

Also, VB.NET does not support default properties, so migrating code is easier if the properties are already in code.
0
 
LVL 28

Assisted Solution

by:AzraSound
AzraSound earned 25 total points
ID: 12288435
I always type in the property, even if it is the default.  It's "cleaner" and there is no ambiguity, especially since not all object's have the same default property.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12288443
Thanx guys. : )
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 87
using Access 8 58
passing a value with stream reader AFTER a ";" 3 58
VB 6 error 5 in windows 10 but not in XP 7 40
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now