Content Rotator Component
Content Rotator Component คืออะไร
Content Rotator Component เป็นคอมโพเนนท์ที่ใช้สำหรับการแสดง
html ที่สามารถวนไปเรื่อยๆ ตามจำนวนข้อมูลที่มีอยู่ ในแต่ละครั้งที่มีคนเข้ามาดูข้อมูลหน้านั้น
หรือ มีการกด Refresh ข้อมูลที่แสดงก็จะวนไป ทำให้ผู้ใช้เห็นข้อมูลที่ไม่ซ้ำกัน
โดยข้อมูลที่แสดง ออกมาอาจจะเป็น ข้อความ, รูปภาพ, หรือ ลิงค์ต่างๆ เราสามารถนำคอมโพเนนท์อันนี้มาใช้ในการแสดง
ข้อความทักทายแบบต่างๆ หรือ แม้กระทั่งใช้แสดงโฆษณาก็ได้เช่นกัน
รูปแบบ
<%
Set
cr=Server.CreateObject("MSWC.ContentRotator")
%>
|
ต่อไปจะเป็นการเสนอตัวอย่าง โดยให้ทำการสร้างไฟล์
"textads.txt" ไว้ใน root ของเว็บ แล้วทำการป้อนค่าดังในตาราง
"textads.txt" :
%% #1
This is a great day!!
%% #2
<h1>Smile</h1>
%% #3
<img src="smiley.gif">
%% #4
Here's a <a href="http://www.sourcecode.in.th">link.</a> |
เครื่องหมาย #จะนำหน้าตัวเลขที่บอกตำแหน่งของแต่ละข้อมูล
โดยในการแสดงผลจะเริ่มจากหมายเลข น้อยๆ ไปยัง หมายเลขมากๆ แล้วก็วนไปเรื่อยๆ
ต่อมาให้ทำการสร้างไฟล์ asp แล้ว ป้อนโค้ดต่อไปนี้:
<html>
<body>
<%
set cr=server.createobject("MSWC.ContentRotator")
response.write(cr.ChooseContent("textads.txt"))
%>
</body>
</html> |
ต่อไปจะเป็นตารางของ เมทธอดต่างๆของ
Content Rotator Component:
Methods
Method |
Description |
Example |
ChooseContent |
Gets and displays a content string |
<%
dim cr
Set cr=Server.CreateObject("MSWC.ContentRotator")
response.write(cr.ChooseContent("textads.txt"))
%>
Output:

|
GetAllContent |
Retrieves and displays all of the
content strings in the text file |
<%
dim cr
Set cr=Server.CreateObject("MSWC.ContentRotator")
response.write(cr.GetAllContent("textads.txt"))
%>
Output:
This is a great day!!
Smile
Here's a link.
|
สังเกตุผลที่ได้จากแต่ละเมทธอด
|