ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

Don't use the Default Web Site
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

What's the difference between objRS("name") and objRS.Fields("name")?

In an effort to prove that I do occasionally manage to wade through all the spam and read a message from our users, I figured I'd tackle one I received the other day. Here's the question...

Actually, this is a humble request for you to write an article! I often see the following references to table values. Please explain the differences (not that I see any), as well as which is preferred / best.



For the most part, you're right... In VBScript there is almost no difference.

The reason behind the confusion is what are called default properties. Many objects have a property that is the default returned when a specific one is not asked for. Using the example above...

  • The default property of an Item object in the Fields collection is it's Value.
  • The default property of the Fields collection is the Item object.
  • The default property of an ADO recordset object is it's Fields collection.

As a result... you can leave all the defaults out and your script runs the same as if you had explicitly specified them. While default properties can make code easier to write, they also have several drawbacks, the most problematic of which is often readability by other people who are not familiar with the objects being used. Sure most programmers will figure out an ADO recordset, but what about those custom business logic components?

Another problem now that VB.NET is out is that it handles default properties a little differently then VBScript and VB 6. For more information check out MSDN: Default Property Changes in Visual Basic.

So as to which format is best... in general it's better to spell out exactly what you mean. It helps avoid confusion and you'll have fewer problem when you upgrade/switch to VB.NET. That being said... if you look at my code you'll tend to see this format: objRecordset.Fields("field_name"). It always seemed the most reasonable (and readable) to me... or then again maybe I'm just lazy.  ;)  I guess this is one of those "do as I say and not as I do" scenarios.

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers