利用ASP和Access数据库制作局域网网上答题系统

信息社会对人的学历、素质要求越来越高,人们为了找到前途更好、收入更加诱人的工作岗位,必须通过各种各样的考试如注册会计师资格考试、司法资格考试等等,而各种各样的试题资料也应运而生,但所有的资料所共有的一个缺点就是使用上的不方便、不灵活、及效率不高,本网上答题系统正是为了弥补这些诸多不便而编制的、适合于局域网并能在单机上运行的系统,下面就详细介绍本系统的编制及使用方法。
一、界面
如图所示:

二、程序组成
本系统由Index. asp、Lkzk.asp、Save.asp、Db0.fun 四个小程序及Access数据库文件lkzk.mdb组成各程序的功能分别是:
1. Index. asp 是框架网页,负责导入Lkzk.asp、Save.asp两个子网页组成完整的程序页面。
2. Lkzk.asp 是随机出题答题的交互页面生成程序,主要完成随机选题、题目显示、答案输入及正确率、总答题数显示等功能。
3. Save.asp 完成答题正误判断、显示及成绩登记(按客户端IP地址)。
4. Db0.fun 包含打开Access数据库的多个函数(Lkzk.asp、Save.asp都用到的)。
5. lkzk.mdb Access数据库文件,由表“IP”和表“题库”组成。
表(IP)由编号字段ID(数字格式)、客户机地址字段IP(文本格式)、错误答案数字段nnn(数字格式)、正确答案数字段yyy(数字格式) 所组成;
表“题库” 由题号字段ID(数字格式)、单选多选标记字段dx(数字格式)、答案字段xz(文本格式)、试题内容字段na(备注格式)所组成。(注:试题内容的选择部分必须为“A. …… B. …… C. …… D. ……” 格式)
--------------- Index. Asp-----------------

 1<html>
 2<head>
 3<title>网上司考试题库</title>
 4</head>
 5<frameset framespacing="0" rows="87%,*">
 6<frame name="top" scrolling="auto" src="lkzk.asp"/>
 7<frame marginheight="0" marginwidth="0" name="bottom" scrolling="auto"/>
 8<noframes>
 9<body>
10<p>此网页使用了框架,但您的浏览器不支持框架。</p>
11</body>
12</noframes>
13</frameset>
14</html>

--------------Lkzk.asp-------------

1   
2Set rsu2 = GetMdbStaticRecordset("lkzk.mdb", "IP")   
3Set rs = GetMdbStaticRecordset("lkzk.mdb", "题库")   
1<html>
2<head>
3<title>网上司考试题库</title>
4</head>
5<body>
6<font color="#000080" size="4">司考试题库   

ClientIP = Request.ServerVariables("REMOTE_ADDR")
userIP=Right(ClientIP,Len(ClientIP)-InStrRev(ClientIP,"."))
rsu2.AbsolutePosition=userIP
Randomize
I=Fix(Rnd*1800)
rs.AbsolutePosition=I+1

1总第```
2=CStr(I+6)
3```题 ```
4'=rs("type")

``` s=rs("na") x=InStr(s,"A.") sx="多选" if rs("dx")=0 then sx="单选" end if ``` ``` =Left(s,x-1) ``` '显示除选择部分外的试题内容 ``` =sx ```
'显示是单选还是多选题
``` s=Right(s,Len(s)-x+1) x=InStr(s,"B.") ``` '以下开始显示复选框及选择部分 ``` =Left(s,x-1) ```
``` s=Right(s,Len(s)-x+1) x=InStr(s,"C.") ``` ``` =Left(s,x-1) ```
``` s=Right(s,Len(s)-x+1) x=InStr(s,"D.") ``` ``` =Left(s,x-1) ```
``` s=Right(s,Len(s)-x+1) ``` ``` =s ```
继续做题
``` if rsu2("nnn")+rsu2("yyy")=0 then rsu2("yyy")=1 end if ``` 正确率:``` =FormatNumber(rsu2("yyy")/(rsu2("nnn")+rsu2("yyy"))*100, 2, True) ```% 总答题数:``` =rsu2("nnn")+rsu2("yyy") ```
\-----------------Save.asp------------------- ```

Set rsu2 = GetMdbStaticRecordset("lkzk.mdb", "IP")
Set rs = GetMdbStaticRecordset("lkzk.mdb", "题库")

1<html>
2<body>   

I=CInt(Request("AI"))
rs.AbsolutePosition=I+1
ssx="错"
A=Replace( Request("A"), ", ", "" )
if A=rs("xz") then '判断答题正误
ssx="对"
end if

1<font color="Red">   
2您答```
3=ssx
4```了 '显示答案正误等信息   
5</font>   
6试题库总第```
7=CStr(I+1+5)
8```题 您的答案是:```
9=A

参考答案是:``` =rs("xz")

ClientIP = Request.ServerVariables("REMOTE_ADDR")
userIP=Right(ClientIP,Len(ClientIP)-InStrRev(ClientIP,"."))
rsu2.AbsolutePosition=userIP
rsu2.Update
If ssx="对" then
rsu2("yyy") =rsu2("yyy")+1
End if
if ssx&lt;&gt;"对" then
rsu2("nnn") =rsu2("nnn")+1
End if
rsu2.Update '以下将正误结果记录于数据库表“IP”中

1</body>
2</html>   
3\--------------Db0.fun----------------   

' 以下为函数程序
'---------------------------------------------------
Function GetMdbConnection( FileName )
Dim Provider, DBPath
Provider = "Provider=Microsoft.Jet.OLEDB.4.0;"
DBPath = "Data Source=" &amp; Server.MapPath(FileName)
Set GetMdbConnection = GetConnection( Provider &amp; DBPath )
End Function
'---------------------------------------------------
Function GetMdbRecordset( FileName, Source )
Set GetMdbRecordset = GetMdbRs( FileName, Source, 2, "" )
End Function
'---------------------------------------------------
Function GetMdbStaticRecordset( FileName, Source )
Set GetMdbStaticRecordset = GetMdbRs( FileName, Source, 3, "" )
End Function
'---------------------------------------------------
Function GetConnection( Param )
Dim conn
On Error Resume Next
Set GetConnection = Nothing
Set conn = Server.CreateObject("ADODB.Connection")
If Err.Number &lt;&gt; 0 Then Exit Function
conn.Open Param
If Err.Number &lt;&gt; 0 Then Exit Function
Set GetConnection = conn
End Function
'---------------------------------------------------
Function GetMdbRs( FileName, Source, Cursor, Password )
Dim conn, rs
On Error Resume Next
Set GetMdbRs = Nothing
If Len(Password) = 0 Then
Set conn = GetMdbConnection( FileName )
Else
Set conn = GetSecuredMdbConnection( FileName, Password )
End If
If conn Is Nothing Then Exit Function
Set rs = Server.CreateObject("ADODB.Recordset")
If Err.Number &lt;&gt; 0 Then Exit Function
rs.Open source, conn, Cursor, 2
If Err.Number &lt;&gt; 0 Then Exit Function
Set GetMdbRs = rs
End Function
'---------------------------------------------------

1三、运行方法   
2本系统运行方法是先按文中所述格式制作好试题库文件Lkzk.mdb连同上列四个程序COPY至主机的WWW 的根目录中并执行http://主机IP地址/Index.asp即可进行答题。(本程序在单机windows98+pws+ODBC驱动 及局域网windowsNT Server4.0 +IIS4.0+ODBC驱动 环境下均测试通过,各用户可以根据具体情况对程序中的标题稍加修改制作自己的试题库系统,还可以对其进行扩充增加各类其它功能,在这里因篇幅关系就不再敷述,有关ODBC驱动的详细情况可参阅相关资料或给我来信mailto: [email protected] 。</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus