구글와이드(336x280)_상단 2개


(영문)ASP Object - Tutorial ASP, ASP.NET

ASP Object

Objects are a way of encapsulating multiple methods (they're like functions) and variables in one easy to manage Uber-Variable (an Object). Objects in ASP resemble other Object Oriented Programming languages. In this lesson we will be using the ASP CDO.Message object as our example object to be dissected.

ASP Object Overview

Objects were created to combat the increasing complexity of programming. The rationale for understanding and using Objects in your programming is to make programming easier and your code more human readable.

ASP Create an Object - Server.CreateObject

An object in ASP is created by passing a name string to the Server.CreateObject function(actually referred to as a method). The string to create a Message object is "CDO.Message". We will be creating a CDO.Message object in this example.
Note: Because objects are special there is a special way that you create and destroy them using the Set keyword. These areas are marked in red in the example below.

ASP Code:

<%
Dim myObject
Set myObject = Server.CreateObject("CDO.Message")

'You must Set your objects to "nothing" to free up the
'the computer memory that was allocated to it
Set myObject = nothing
%>
That wasn't too painful, was it? Let's cover some more bases on the object model.
Objects are a collection of related things that are combined into this blob of programming goo that can be created and destroyed whenever we may need it. For example say that you wanted to make an object that allowed you to send an email...
Well there are certain things all emails have: To, From, CC, Subject, etc. This list of variables that are common to every email would be quite tiresome to have to create for every email we sent. Wouldn't it be nice if we could create some sort of Uber-Variable(Object) that would group all these smaller variables into one thing?

ASP Object Properties

These smaller variables are commonly referred to as an object's properties and the format for setting these properties is nearly identical to setting a variable equal to a value.
The correct syntax for setting an object's properties is:
  • objectName.propertyName = someValue
In this tiny example below we are creating a new mail object and setting its To and From properties.

ASP Code:

<%
Dim myObject
Set myObject = Server.CreateObject("CDO.Message")

'Then we set the To and From properties
myObject.To = "little.timmy@example.com" myObject.From = "huge.jill@example.com"

'You must Set your objects to "nothing" to free up the
'the computer memory that was allocated to it
Set myObject = nothing
%>
Now I know we didn't DO anything in the above example, but we still need to learn a bit more about objects before we can get anything done! Objects, besides having a clump of associated common variables, may also have a collection of functions(which become referred to as methods) associated with them.
These methods are processes that you would want to commonly do to either manipulate the variables of the object or to use the variables to do something. In our Message object we have a collection of information that, when put together into the proper email form and sent to an email service will become an email.
All this complex code has been programmed by Microsoft employees and stored into the Message objects Send method.

ASP Object Methods

We cannot see the code that was used to program the Send method, but that's one of the great things about using object programming. You know what you need to know and nothing more. In our example below we create a Message object and set the necessary properties and send it off with the Send method.

ASP Code:

<%
Dim myObject
Set myObject = Server.CreateObject("CDO.Message")

'Then we set the To and From properties
myObject.To = "little.timmy@example.com"
myObject.From = "huge.jill@example.com"
myObject.Subject = "Can you see me?"
myObject.TextBody = "I'm really really big!"

myObject.Send()

'You must Set your objects to "nothing" to free up the
'the computer memory that was allocated to it
Set myObject = nothing
%>
Note:If you are running this on your home computer there are a slough of issues that may arise with sending an email. Microsoft has a large FAQ about using the CDO.Message object that may help you. Knowing Microsoft, that link may go dead soon, so Contact Us if it expires!

ASP Object Summary

In this lesson you learned how to create and destroy an object in ASP. You also learned how to access the properties and utilize the methods of an object. If you still have no idea what this lesson was about, hopefully there's enough information for you to hack out what you need to do in your ASP project.
However, there are many good references to object oriented programming and here are a few to help out those that would like a crash course: Sun's Take on Objects, Crazy Germans Know Their Stuff!, and Wikipedia.



null



바보들의 영문법 카페(클릭!!)

오늘의 메모....

시사평론-정론직필 다음 카페
http://cafe.daum.net/sisa-1

바보들의 영문법 다음 카페
http://cafe.daum.net/babo-edu/

티스토리 내 블로그
http://earthly.tistory.com/

내 블로그에 있는 모든 글들과 자료에 대한 펌과 링크는 무제한 허용됩니다.
(단, 내 블로그에 덧글쓰기가 차단된 자들에게는 펌, 트랙백, 핑백 등이 일체 허용되지 않음.)

그리고 내 블로그 최근글 목록을 제목별로 보시려면....
바로 아래에 있는 이전글 목록의 최근달을 클릭하시면 됩니다.
그러면 제목을 보고 편하게 글을 골라 보실 수 있습니다.

그리고 내 블로그내 글을 검색하시려면 아래 검색버튼을 이용하시면 됩니다.


가가챗창

flag_Visitors

free counters