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 = "webmaster@asp101.com"
objCDOMsg.To = "john@asp101.com"
objCDOMsg.Subject = "With Tip Test Subject"
objCDOMsg.TextBody = "This is a test email."
objCDOMsg.Send
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 = "webmaster@asp101.com"
.To = "john@asp101.com"
.Subject = "With Tip Test Subject"
.TextBody = "This is a test email."
.Send
End WithSet 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.
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.