งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

ASP & Text File Computer Science, BUU.

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "ASP & Text File Computer Science, BUU."— ใบสำเนางานนำเสนอ:

1 ASP & Text File Computer Science, BUU

2 FileSytem Object ใช้สำหรับสร้าง เขียนและอ่านไฟล์ข้อความ มี 2 method
CreateTextFile Method OpenTextFile Computer Science, BUU

3 [object.]CreateTextFile(filename[,overwrite[,unicode]])
จะเป็นการสร้างไฟล์ข้อความขึ้นมาใหม่ โดยมีวิธีการใช้งานดังนี้ [object.]CreateTextFile(filename[,overwrite[,unicode]]) Computer Science, BUU

4 พารามิเตอร์ต่างๆ ในเมธอด CreateTextFile
พารามิเตอร์ ค่าที่กำหนด filename ชื่อไฟล์ข้อความที่จะสร้าง overwrite true คือให้สร้างทับไฟล์ข้อความเดิม (หากมีอยู่แล้ว) false คือไม่ให้สร้างทับไฟล์ข้อความเดิม unicode true คือสร้างเป็นไฟล์ข้อความชนิด unicode false คือสร้างเป็นไฟล์ข้อความชนิด ASCII (ค่าปกติคือ false หรือเป็นไฟล์ข้อความชนิด ASCII) Computer Science, BUU

5 ตัวอย่าง demo1.asp <%
Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile(”demo1.txt",true) a.WriteLine("Text file นี้สร้างจาก demo1.asp") a.Close %> Computer Science, BUU

6 เมธอด OpenTextFile เมธอดนี้จะใช้ในการอ่านไฟล์ข้อความ ไม่ว่าจะเป็นไฟล์ข้อความที่ สร้างขึ้นจากเมธอด CreateTextFile หรือจะเป็นไฟล์ข้อความที่สร้างมา จากวิธีการอื่นๆ ก็ได้ โดยมีรูปแบบการใช้งานดังนี้ [object.]OpenTextFile(filename[,iomode[,create[,format]]]) Computer Science, BUU

7 พารามิเตอร์ต่างๆ ในเมธอด OpenTextFile
พารามิเตอร์ ค่าที่กำหนด filename ชื่อไฟล์ข้อความที่จะสร้างใหม่หรือเปิดขึ้นมา iomode = เปิดไฟล์เพื่ออ่าน 8 = เปิดไฟล์เพื่อเขียนต่อเติม create true คือถ้าไม่พบไฟล์ที่กำหนด ให้สร้างไฟล์ขึ้นใหม่ false คือถ้าไม่พบไฟล์ที่กำหนด จะไม่สร้างไฟล์ขึ้น ใหม่ format ไม่ระบุให้คือ ascii Computer Science, BUU

8 ตัวอย่าง demo2.asp <% ForReading=1
Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.OpenTextFile(”C:\asp\demo1.txt",ForReading) Response.Write(a.readLine()) a.Close %> Computer Science, BUU

9 ตัวอย่าง demo3.asp เพิ่มข้อมูล
<% ForAppend =8 Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.OpenTextFile(”C:\asp\demo1.txt",ForAppend) a.WriteLine(“บรรทัดที่เพิ่มใหม่”) a.Close %> Computer Science, BUU

10 ตัวอย่าง demo4.asp อ่านข้อมูล
<% ForReading=1 Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.OpenTextFile(”demo.txt",ForReading,False) Do while not a.AtEndOfStream Response.Write(a.readLine() & "<BR>") loop a.Close %> Computer Science, BUU

11 ตัวอย่าง demo5.asp กระดานข่าว บริษัท ABC มหาชน จำกัด<hr> <%
' อ่านข้อความเดิมมาแสดงก่อน ForReading=1 Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.OpenTextFile("webboard.txt",ForReading,False) do while not a.atendofstream response.write(a.readLine() & "<BR>") loop a.Close %> Computer Science, BUU

12 <form action=”demo5-1.asp" method="post">
ข้อความที่จะประกาศ : <textarea rows="5" cols="70" name="message" ></textarea> <br> ผู้ประกาศ : <input type="text" name="by"> <input type="Submit" value="ส่ง"> <input type="reset" value="ยกเลิก"> </form> <hr> Computer Science, BUU

13 ตัวอย่าง demo5-1.asp กระดานข่าว บริษัท ABC จำกัด<hr> <%
'รับข่าวใหม่ gnew=Request.Form("message") gby=Request.Form("by") ForAppend=8 Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.OpenTextFile("Webboard.txt",ForAppend,True) a.writeline("ข้อความ : " & gnew) a.writeline("โดย : " & gby) 'now หมายถึงวันเวลาปัจจุบัน a.writeline("วัน-เวลา : " & now & "<HR>") a.Close %> Computer Science, BUU

14 ข้อที่เพิ่มเข้าไปคือ : <%=gnew%><br>
ส่งมาโดย : <%=gby%><br> เพิ่มแล้วเมื่อ <%=now%><hr> <a href=”demo5.asp">กลับไปกระดานข่าว </a> <hr> Computer Science, BUU

15 การสร้างแฟ้มตัวนับด้วยแฟ้ม Text File
การสร้างตัวนับเป็นแบบไฟล์ข้อความ ( text file ) จะใช้ Component ชื่อ FileSystemObject ในการสร้างเอกสาร ASP ซึ่งเมื่อสร้างไว้แล้วสามารถใช้งานร่วมกับเอกสาร ASP อันอื่นได้ การสร้างตัวนับแบบเก็บลงในแฟ้มเก็บบันทึกค่าจำนวนลงในฐานข้อมูลหรือลงไฟล์ข้อความ เวลาต้องการใช้ก็อ่านขึ้นมาแล้วนำไปแสดงผลในแบบข้อความ Computer Science, BUU

16 ขั้นตอนวิธีในการสร้างแฟ้ม ตัวนับแบบ
เริ่มต้นโปรแกรม เปิดแฟ้มข้อความ เพื่ออ่านข้อมูล ถ้าไม่มีแฟ้มข้อความก็สร้างขึ้นมาใหม่และให้ค่าเริ่มต้นของตัวนับเป็น 0 ถ้ามีข้อมูลแล้วก็อ่านข้อมูลเข้ามาเก็บในตัวแปรตัวนับ เพิ่มตัวนับอีกหนึ่ง เปิดแฟ้มข้อความแล้วเขียนทับลงไปในแฟ้มนั้น ปิดแฟ้มข้อความ แสดงค่าในตัวนับ จบโปรแกรม Computer Science, BUU

17 <Script Language="VBScript" RunAT="Server">
Count.inc <Script Language="VBScript" RunAT="Server"> Function Counter(countfile) textfile=server.mappath(countfile) ForReading=1 Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.OpenTextFile(textfile,ForReading,0) if a.AtEndOfStream then count=0 else count=a.readline() end if count=count+1 Set a = fs.CreateTextFile(textfile) a.writeline(count) a.close Counter=count End Function </Script> Computer Science, BUU

18 Count.asp <%gCount=Counter(”count.txt")%> <table border=1>
<tr><td>Web page นี้ถูกเปิดอ่านเป็นครั้งที่</td></tr> <tr><td> <font face="MS comics" size="5"><%=gCount%></font></td></tr> <tr><td> <font face="Impact" size="7"><%=gCount%></font></td></tr> </table> <!--#include file="counter.inc"--> Computer Science, BUU


ดาวน์โหลด ppt ASP & Text File Computer Science, BUU.

งานนำเสนอที่คล้ายกัน


Ads by Google