ASP 101 - Active Server Pages 101 - Web06
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

Use transactions wherever possible
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Use With When Working With Objects

Normally when you instantiate an object it's because you're about to do something with it. In fact you'll probably end up doing a lot of things with it. To save yourself some typing and to make things easier to read try this.

Let's assume we're sending an email. Here's a quick sample script to do just that:

Dim objCDOMsg
Set objCDOMsg = Server.CreateObject("CDO.Message")
objCDOMsg.From     = ""
objCDOMsg.To       = ""
objCDOMsg.Subject  = "With Tip Test Subject"
objCDOMsg.TextBody = "This is a test email."
Set objCDOMsg = Nothing

That script works fine, but take a look at this one which utilizes the With statement:

Dim objCDOMsg
Set objCDOMsg = Server.CreateObject("CDO.Message")
With objCDOMsg
    .From     = ""
    .To       = ""
    .Subject  = "With Tip Test Subject"
    .TextBody = "This is a test email."
End With
Set objCDOMsg = Nothing

Not only is this style easier to read, there's also less repetition and hence less chance for silly typos. And if you ever decide you need to rename your object, it makes that process easier as well.

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