ASP learning the FSO component Operation example Skill (8)

Source: Internet
Author: User
fso| Skills

Now, you may have learned a lot, but you may ask: what is the role of this in the FSO file operation?

The following is our topic: Use the FSO for simple text voting.

The main point of the voting page is to show the number of votes for each item and assign it to a variable. The voting is then judged by adding 1 to the voting value and then continuing to write all values to the text.

1, an HTML form page website.html

To do voting click on the platform.

Now, you may have learned a lot, but you may ask: what is the role of this in the FSO file operation?
The following is our topic: Use the FSO for simple text voting.

<form action= "result. ASP "method=" POST ">
<input type= "Radio" name= "website" value= "A" checked> cnbruce.com<br><input "type=" Radio "name=" website "Value=" B "> Blueidea.com<br><input type=" Radio "name=" website "value=" C "> it365cn.com<br>< Input type= "Radio" name= "website" value= "D" > 5d.cn<br><input type= "Submit" ><input type= "reset" >

2, result.asp to accept the form page value

  <%whichfile=server.mappath ("Site.txt")
  set fso=createobject (" Scripting.FileSystemObject ")
  set thisfile=fso.opentextfile (whichfile)
  my_string= Thisfile.read
  linea_num = InStr (my_string, "A")
  b_num = InStr (my_string, "B")
  c_num = InStr (My_string, "C")
  d_num = InStr (my_string, "D")
  total_num = Len ( my_string)
  a_value = Mid (my_string,a_num+1,b_num-a_num-1)
  b_value = Mid (my_string,b_ num+1,c_num-b_num-1)
  c_value = Mid (my_string,c_num+1,d_num-c_num-1)
  d_value = Mid (my _string,d_num+1,total_num-d_num)
  select case Request.Form ("website")
  case "A": A_ Value=a_value+1
  case "B": b_value=b_value+1
  case "C": c_value=c_value+1
   case "D": d_value=d_value+1
  end Select
  mynew_string= "A "& CStr (A_value) &" B "& CStr (B_value) &" C "& CStr (C_value) &" D "& CStr (d_value)
  ;  set Newfile=fso.createtextfile (Whichfile)
  newfile.writeline (mynew_string)
   Newfile.closeset fso=nothing%> Current voting:<br>cnbruce.com:<%=a_value%>
  <br> Blueidea.com:<%=b_value%><br>
  it356cn.com:<%=c_value%><br>
   5d.cn:<%=d_value%><br>
  <a href= "website.html" > Back to continue </a>

With the basis of the above function, it should not be difficult to see this.

3, in the end don't forget the Count file Site.txt

Format: A1B1C1D1

Debugging

OK, three files can be qualified for a very simple voting system, if you want to strengthen, the need to refine the combination of previous knowledge, such as a vote after a session or cookies, when the vote again to judge if the session or cookies exist is not allowed, It's a simple way to vote and cheat. Of course, more still want to go to the practice of their own.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.